Sometimes I ran across a GitHub merge request of a gem where it was not completely obvious in which version...
In Rails 5+ you can access a helper from a controller using the helpers method: # Inside a controller action
To retrieve only unique combinations of the selected attributes: You can omit rows, where all selected columns are equal with...
Rails includes milliseconds in Time / DateTime objects when rendering them as JSON: JSON.parse(User.last.to_json)['created_at'] #=> "2001-01-01...
Sometimes, the rails dev server doesn't terminate properly. This can for example happen when the dev server runs in...
After upgrading to Rails 6.1.7.2 one of our apps printed a wall of warnings while booting: /var/www/app/shared/bundle/ruby/2.6.0/gems/net-protocol-0.2.1/lib/net/protocol.rb:68: warning: already...
Using ActiveRecord's #signed_id and .find_signed methods you can create URLs that expire after some time. No conditionals...
When an object is created / updated, various callbacks are executed in this order: before_validation after_validation before_save
Bundler so far ignored the version specified under BUNDLED_WITH in the Gemfile.lock. This had two annoying consequences:
Our CI setup frequently sees this error while running yarn install: yarn install v1.22.19 [1/4] Resolving packages... [2/4] Fetching packages...
In a Jasmine spec you want to spy on a function that is imported by the code under test. This...
Instead of cobbling together default settings in several different places as the issues arise, you can define them application-wide...
tl;dr You should decouple migrations from models by embedding models into the migration. To use STI in this scenario...
This can happen with a very simple model: class Note has_many :attachments end Everything looks normal: Note.all.to_a.size # => 8 Note.all.ids.size...
Large Rails projects tend to define multiple custom ways to format Dates or DateTimes. This often leads to duplicated format...
Unpoly's [up-observe], [up-autosubmit] and [up-validate] as well as their programmatic variants up.observe() and up.autosubmit...
tl;dr Since Rails 7+ you can use ComparisonValidator for validations like greater_than, less_than, etc. on dates, numerics...
You can use ETags to allow clients to use cached responses, if your application would send the same contents as...
tl;dr git checkout is the swiss army of git commands. If you prefer a semantically more meaningful command for...
Ruby's standard library includes a class for creating temporary directories. Similar to Tempfile it creates a unique directory name...
tl;dr Since Rails 6+ you can use before? and after? to check if a date/time is before or after...
To allow HTTP 304 responses, Rails offers the fresh_when method for controllers. The most common way is to pass...
A memory leak is an unintentional, uncontrolled, and unending increase in memory usage. No matter how small, eventually, a leak...
For Rails models where only one of multiple attributes may be filled out at the same time, there is no...