Whenever you create a table from a database migration, remember to add updated_at and created_at timestamps to that...
Rails has always included a scaffold script that generates a default controller implementation for you. Unfortunately that generated controller is...
When writing Rails migrations to convert a string column to an integer you'd usually say: change_column :table_name...
I recently experienced the error ActiveRecord::StatementInvalid: Mysql2::Error: closed MySQL connection. Apparently this happens when there is a timeout...
dusen 0.4.8 and edge_rider 0.2.3 no longer depend on Rails (they still depend on ActiveRecord). That means you can...
When you're writing migrations that do more than changing tables (like, modify many records) you may want some output...
We tend to use database transactions as a magic bullet to get rid of all our concurrency problems. When things...
Remember why preloading associations "randomly" uses joined tables or multiple queries? If you don't like the cleverness of this...
Active Record's select method allows you to make use of the power of MySQL select statements. On the one...
Merge requests are often rejected for similar reasons. To avoid this, before you send a merge request, please confirm that...
You have multiple options: Just don't have a type column. All STI magic will be disabled automatically.
ActiveRecord translations live in locale.activerecord. ActiveModel translations live in locale.activemodel. To use the same translations for both, use YAML references...
Authentication is hard: there are many edge cases, and most users (including yourself) usually only go the "happy path" once...
We have often felt the pain where our models need to serve too many masters. E.g. we are adding a...
In the following example the method update_offices_people_count won't be called when office_id changes, because it...
Rails gives you migrations to change your database schema with simple commands like add_column or update. Unfortunately these commands...
Caution when using .where to exclude records from a scope like this: # Fragile - avoid User.where("id NOT IN (?)", excluded_ids...
All columns of a model's database table are automagically available through accessors on the Active Record object.
Rails has generic error messages you can define in your locale .yml files. You may override those application-wide error...
Sometimes you might want to limit the number of associated records in a has_many association, but cannot add a...
Rails understands a :limit options when you create columns in a migration. Its meaning depends on the column type, and...
TL;DR: You should generally use #size to count associated records. size Counts already loaded elements If the association is...
If you need to capture signatures on an IPad or similar device, you can use Thomas J Bradley's excellent...
This page lists many query methods and options in ActiveRecord which do not sanitize raw SQL arguments and are not...