Rails 5 has added OR method to Active Relation for generating queries with OR clause. >> Post.where(id: 1).or(Post.where...
Rails 5 introduces ArrayInquirer that wraps an array object and provides friendlier methods to check for the presence of elements...
In Rails 4.x we have transactional fixtures that wrap each test in a database transaction. This transaction rollbacks all...
Consider the following form which has only one input role_id which is accepted through collection_radio_button.
In Rails 4.x, it is not possible to have destroy dependency on both sides of a bi-directional association...
In Rails 4.x, when we save an ActiveRecord object then Rails automatically updates fields updated_at or updated_on...
With large data set we can run into memory issue. Here is an example. >> Post.published.count => 25000 >> Post.where(published: true).each...
For example we have a view and a partial view named index.html.erb and _todo.html.erb. /app/views/todos/index.html.erb <%= render partial: 'todo', collection: @todos...
We sometimes need unique and random tokens in our web apps. Here is how we typically build it.
### Rails 4.x ### class PostsController < ApplicationController # HTTP_REFERER is not present and it throws exception rescue_from ActionController::RedirectBackError, with...
In Ruby on Rails 5 belongs_to associations required by default so the following code: class User < ApplicationRecord end