When your public-facing application has a longer downtime for server maintenance or long migrations, it's nice to setup...

You need to set the :inverse_of option manually for relations that have an association to a polymorphic model. Otherwise...

After loading a staging dump into development, you might get an ActiveRecord::EnvironmentMismatchError when trying to replace the database (like...

When localizing model attributes via I18n you may run into errors like this: I18n::InvalidPluralizationData: translation data {...

...} can not be...

There are many approaches out there how you can import data from a legacy application to a new application. Here...

github.com

Use Traim to build a RESTful API for your ActiveRecord models with very little code. Traim assumes your API resources...

You can not use the hash_including argument matcher with a nested hash: describe 'user' do let(:user) { {id: 1...

ActiveRecord::RecordNotFound errors provide quite meaningful error messages that can provide some insight on application details. Consider the following:

This card will show you a cool way to define a class using Struct.new. A common usecase for Structs are...

Since Rails 5, domain models inherit from ApplicationRecord by default. This is the place to put code that should be...

Rails supports time zones, but there are several pitfalls. Most importantly because Time.now and Time.current are completely different things and...

Database connections are not thread-safe. That's why ActiveRecord uses a separate database connection for each thread.

makandra dev

This card compares patterns to store trees in a relation database like MySQL or PostgreSQL. Implementation examples are for the...

github.com

The parallel-gem is quite easy to use and can speed up rendering time if you want to render the...

makandra dev

This is a visualization of the files that will be generated by some useful rails generators. Invoke a generator from...

Like you know from "How to tell ActiveRecord how to preload associations (either JOINs or separate queries)", you can tell...

When you're writing specs for ActiveRecord models that use memoization, a simple #reload will not do: it 'updates on...

github.com

Closure_tree lets your ActiveRecord models act as nodes in a tree data structure. This promises a few improvements over...

api.rubyonrails.org

Instantiating ActiveRecord objects comes expensive. To speed up things, you can choose a more direct way to talk to your...

api.rubyonrails.org

When working with custom transactions and use ActiveRecord::Rollback you may encounter unexpected behaviour if you try to roll back...

#reverse_order does not work with complex sorting constraints and may even silently create malformed SQL for rails < 5.

davidverhasselt.com

Rails 5 / 6 / 7 Method Uses Default Accessor Saves to Database Runs Validations Runs Callbacks Updates updated_at/updated_on Respects Readonly...

Detect if a gem has been activated A gem is activated if it is either in the current bundle (Gemfile.lock...

github.com

We have released a new library Gemika to help test a gem against multiple versions of Ruby, gem dependencies and...