PostgreSQL can cosplay as a full-text search engine. It doesn't have the features or fidelity of ElasticSearch or...

...like using the /slackfont command. Fonts need to be installed on your machine. Webfonts beyond those provided by Slack won't magically work unless you install them locally.

thepugautomatic.com

How a macro can dynamically define a method that can be overridden with super in the same class.

Some pseudo-elements need to be addressed with vendor prefixes. E.g. ::selection is not supported by Firefox, you need to...

If you want to collapse/expand elements with dynamic content (and thus unknown height), you can not transition between height: 0...

Git commits should be very deliberate, and only contain changes that you really want to be in there. In order...

The change_column method for rails migrations support casting with a custom SQL statement. This allows us to change a...

Whenever you create a table from a database migration, remember to add updated_at and created_at timestamps to that...

ruby-doc.org

...read and write access by methods like File.open and File.read. def exclusively_locked_access begin @file_locked = true File.open(F"#{file_path}.lock"), 'w+') do |f| f.flock(File::LOCK_EX...

...that block make sure to do that manually and preferably wrap it it with begin and rescue if something might go wrong: begin f = File.open(file, File::CREAT) f.flock(File...

While verifying doubles in RSpec is a good default, it is limited in the amount of methods it actually is...

Debugging your integration tests, that run a headless Chrome inside a docker image, is tricky. In many cases you can...

...code comments come into play: Use code comments to document Hows and Whys Group belonging lines with empty lines ("code paragraphs") New code is usually bright and clear to the...

Programatically invoke Rails generators Require the generator, instantiate it and invoke it (because generators are Thor::Groups, you need...

Sometimes we write plain SQL queries in migrations so we don't have to mock ActiveRecord classes. These two migrations...

index 0000000..a51cbad --- /dev/null +++ b/app/models/apple.rb @@ -0,0 +1,9 @@ +class Apple < Fruit + belongs_to :juice, class_name: 'AppleJuice' + + attr_accessor :type + + def to_s + I18n.t(type, scope: 'fruits.apples...

index 0000000..a51cbad --- /dev/null +++ b/app/models/pear.rb @@ -0,0 +1,9 @@ +class Pear < Fruit + belongs_to :juice, class_name: 'PearJuice' + + attr_accessor :type + + def to_s + I18n.t(type, scope: 'fruits.pears...

...move the directory to its new location old_store_path = Pathname.new(old_store_dir) begin FileUtils.rmdir(old_store_path.parent) # cleanup empty directories afterwards rescue Errno::ENOTEMPTY => e # ignore exception for non-empty...

Say you wrap your index view in a form to apply different filters like pagination or a search query. On...

makandra dev

All browsers implement an event named beforeunload. It is fired when the active window is closed and can be used to display an alert to warn the user about unsaved...

...To trigger the alert, you have to call preventDefault() on the event. Note The beforeunload event is only dispatched when the user navigation makes a full page load, or if...

makandra dev

If you want Sidekiq to be able to talk to Redis on staging and production servers, you need to add...

api.rubyonrails.org

...class Image < ActiveRecord::Base; end class Video < ActiveRecord::Base; end class PageVersion < ActiveRecord::Base belongs_to :primary_medium, polymorphic: true # may be Image or Video end class Page < ActiveRecord::Base...

...belongs_to :current_version, class_name: 'PageVersion' end Now, when you load pages and include their current versions' primary media... Page.includes(:current_version => :primary_medium).to_a ... Rails will produce...

...NonExistentClass".constantize # => NameError: uninitialized constant NonExistentClass Dynamic Programming In scenarios where your application’s behavior depends on dynamic constant resolution, safe_constantize may offer a more convenient control flow to...

makandra dev
github.com

...large number of ActiveRecord objects only to collect its ID. Edge Rider has a better way. Your relations gain a method #collect_ids that will fetch all IDs in a...

...number of ActiveRecord objects only to collect its column value. Edge Rider has a better way. Your relations gain a method #collect_column that will fetch all column values in...

makandra dev
tpgi.com

These are the top ten accessibility errors as researched by TPGi, a company focusing on accessibility. See the linked article...

When using Chrome for Selenium tests, the chromedriver binary will be used to control Chrome. To debug problems that stem...