In our continued quest to extract proven code snippets from makandropedia into tested and upgradable gems, we have released Edge...

The Edge Rider gem gives your relations a method #traverse_association which returns a new relation by "pivoting" around a...

TLDR: Ruby class variables (@@foo) are dangerous in many ways. You should avoid them at all cost. See bottom of...

When creating an ActiveRecord with .new, .create or create!, you cannot set the ID attribute (note: When using Machinist's...

There is a bug in ActiveRecord 2.3.x that leads to changes in nested forms getting lost. class Project < ActiveRecord...

Defining one callback several times in the same class behaves different in ActiveRecord and ResourceController. While in ActiveRecord the callbacks...

validates_uniqueness_of is not sufficient to ensure the uniqueness of a value. The reason for this is that in...

Geordi now has a script that runs capistrano with all known deploy targets (i.e. staging, production...). Use with geordi capistrano...

While you are probably using will_paginate to paginate ActiveRecord scopes, it can actually paginate plain Ruby arrays. The resulting...

Our old solution for cronjobs, the "craken" plugin, is no longer maintained and does not work on Rails 3.2+.

ActiveRecord has a feature called counter caching where the containing record in a has_many relationship caches the...

For two years we've been using SearchableTrait which gives models the ability to process Googlesque queries like this: Contact.search...

When you have two models in a has_many, has_one or belongs_to association, the :inverse_of option in...

YourClass.reflect_on_all_associations.map(&:name) Get the class name by calling class_name, or the type of the association (belongs_to, has_many...

In theory you can take any scope and extend it with additional joins or conditions. We call this chaining scopes...

If you require your Rails models manually, pay attention to the path you use. Unless you have...

If your application has forms to edit string fields, you probably want to strip the entered values (remove whitespace from...

blog.codeclimate.com

“Fat models” cause maintenance issues in large apps. Only incrementally better than cluttering controllers with domain logic, they usually represent...

Never ever declare your associations with a string, especially when doing metaprogramming. A common mistake is something like # WRONG

If this happens to you: user.avatar = Avatar.new user.avatar # => nil (where avatar is a belongs_to), you probably declared your association...

Cucumber_rails' old-school web-steps have been deprecated for a while, urging developers to write high-level step definitions...

If you want to update some records with boolean fields in a migration, always remember to set your values with...

Assuming the following sunspot setup of the post class: class Post < ActiveRecord::Base searchable do text :title string :state

Note: Instead of using the method in this card, you probably want to use ActiveType's nested attributes which is...