Using ActiveModel::Dirty for tracking changes
ActiveRecord
comes with a mechanism to track changes to your model with ActiveModel::Dirty
. Lets put it to some use.
How to use Observers in Rails
Observer
pattern provides a simple mechanism for one object to inform a set of interested objects when its state changes.
Behind the scene - Rails Migrate
All migration files in Rails
are by default prefixed with the timestamp which serves as the version number for the migration file. For an instance a migration file with name
20160310141700_create_users.rb
is prefixed with timestamp 20160310141700
.
Eager Load in Rails
Database is considered an expensive resource, and while developing our application we should be particular about the number of DB queries made, in general fewer the DB queries executed, the better the performance.
FactoryGirl with Non ActiveRecord Classes
Creating FactoryGirl
for ActiveRecord
classes is quite handy. Here we will learn creating FactoryGirl
for NonActiveRecord classes.
Use Rails Enums carefully
ActiveRecord enums are really handy but they can be equally evil if not used properly.