Wrap parameters in Rails
ActionController::ParamsWrapper
in Rails is responsible for wrapping the parameters hash into a nested hash.
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
.
Custom Inquirer Similar To ActiveSupport's StringInquirer
This is in continuation with the ArrayInquirer post.
Lets see how to implement a Custom Inquirer
for a Rails model
similar to ActiveSupport StringInquirer and ArrayInquirer
.
Rails 5 introduces ArrayInquirer
Rails 5
introduced ArrayInquirer as a new member to Inquirer family which initially consisted of well known StringInquirer.
Extend Core Classes in Rails
In my previous post, I have explained how to extend ActiveRecord::Base
.
In this post, I will explain how to extend core ruby
or rails
classes in rails
.
Using gon in rails to pass data to javascript
Very often, I have come accross the situation where I need ruby variables in javascript file. Recently, I got to know about a wonderful gem gon which does the work for you. Lets see with an example.
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.
Extend ActiveRecord::Base
In this post, lets see how to extend ActiveRecord::Base
class to add custom methods.