Posted over 5 years ago by Alexander M.

Rails 5 has added OR method to Active Relation for generating queries with OR clause. >> Post.where(id: 1).or(Post.where...

Posted over 5 years ago by Alexander M.

Rails 5 introduces ArrayInquirer that wraps an array object and provides friendlier methods to check for the presence of elements...

Posted over 5 years ago by Alexander M.

In Rails 4.x we have transactional fixtures that wrap each test in a database transaction. This transaction rollbacks all...

Posted over 5 years ago by Alexander M.

Consider the following form which has only one input role_id which is accepted through collection_radio_button.

Posted over 5 years ago by Alexander M.

In Rails 4.x, it is not possible to have destroy dependency on both sides of a bi-directional association...

Posted over 5 years ago by Alexander M.

In Rails 4.x, when we save an ActiveRecord object then Rails automatically updates fields updated_at or updated_on...

Posted over 5 years ago by Alexander M.

With large data set we can run into memory issue. Here is an example. >> Post.published.count => 25000 >> Post.where(published: true).each...

Posted over 5 years ago by Alexander M.

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...

Posted over 5 years ago by Alexander M.

We sometimes need unique and random tokens in our web apps. Here is how we typically build it.

Posted over 5 years ago by Alexander M.

### Rails 4.x ### class PostsController < ApplicationController # HTTP_REFERER is not present and it throws exception rescue_from ActionController::RedirectBackError, with...

Posted over 5 years ago by Alexander M.

In Ruby on Rails 5 belongs_to associations required by default so the following code: class User < ApplicationRecord end

This website uses short-lived cookies to improve usability.
Accept or learn more