...use version 5.2.0 or newer to ensure you can deploy via Capistrano. It's best to use the latest version, as there were multiple issues between 5.2.0 and 7.3.0.

Webpacker uses Babel and Webpack to transpile modern JavaScript down to EcmaScript 5. Depending on what browser a project needs...

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...

If you use third party APT sources you might end up with unmaintained packages after removing the external source or...

makandra is responsible for maintaining about 75 Ruby projects. These projects use a large number of different versions for Ruby...

If your app does not need to support IE11, you can use most ES6 features without a build step. Just...

Looking at the source code of the validates_numericality_of validator, it becomes clear that it converts the attribute in question to either an integer or float: if configuration[:only...

...ActiveRecord::Errors.default_error_messages[:not_a_number]) next end raw_value = raw_value.to_i else begin raw_value = Kernel.Float(raw_value.to_s) rescue ArgumentError, TypeError record.errors.add(attr_name, configuration[:message] || ActiveRecord::Errors.default...

When you have two models in a has_many, has_one or belongs_to association, the :inverse_of option in Rails tells ActiveRecord that they're two sides of the...

...same association. Example with a has_many / belongs_to association: class Forum < ActiveRecord::Base has_many :posts, inverse_of: :forum end class Post < ActiveRecord::Base belongs_to :forum, inverse_of...

When you repeat complex assertions in your tests multiple times, it might be a good idea to extract a custom...

The nokogiri gem provides different packages for several platforms. Each platform-specific variant ships pre-built binaries of libxml2, e.g...

thepugautomatic.com

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

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

...limits_concurrency configuration. Switch to :solid_queue adapter in your test to verify blocking behavior. Job Configuration class MembershipJob < ApplicationJob limits_concurrency(key: ->(membership) { membership }) end The problem

...is blocked') do membership = create_valid_membership(id: 76381) ActiveJob::Base.queue_adapter = :solid_queue begin MembershipJob.perform_later(membership) second_blocked_job = MembershipJob.perform_later(membership) # Verify blocking behavior assert_equal...

If you want someone to be able to access your rails console, but don't want them to be able...

...why we should always use ===, never == Testing the type of a value Understand the benefit of LoDash's _.isEqual What the f*ck JavaScript? Understand that there is no way...

...a callback function which can write it to console.log. Understand why each code block behaves the way it does: Variant 1: Iterating with forEach's callback function const callbacks...

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

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...

I recently encountered this error as I was trying to build assets: $ node esbuild.config.js .../node_modules/esbuild-plugin-browserslist/dist/resolveToEsbuildTarget.js:43 throw new Error('Could...

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...

...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...

github.com

When handling nested hashes the RSpec output is often hard to read. Here the gem super_diff could help.

To allow HTTP 304 responses, Rails offers the fresh_when method for controllers. The most common way is to pass...