Returning an empty scope can come in handy, e.g. as a default object. In Rails 4 you can achieve this...
We upgraded a Rails 2 application to Rails 3.2 and Ruby 2.1, changed the mysql adapter from mysql to mysql2...
This is what worked for me in a Rails 4: # JSON data as first argument, then parameters patch :update, { some...
Modern browsers natively suppport file pickers that allow the user to choose multiple files at once. To activate this feature...
class Document < ActiveRecord::Base scope :any_tags, -> (tags){ where('tags && ARRAY[?]', tags) } scope :all_tags, -> (tags){ where('tags @> ARRAY...
A different take on what we're doing with ActiveType. Since it lives under the rails organization it might be...
To avoid n+1 queries, you want to eager-load associated records if you know you need to access them...
Cookies without an expiration timestamp are called "session cookies". [1] They should only be kept until the end of the...
So you want to organize your I18n using multiple .yml files but your Rails 4.1 application simply won't use...
There are different ways to run rake: On Rails 4.1+ projects, you have Spring and its binstubs which dramatically improve...
In Rails, you can very easily send emails with HTML and plaintext bodies. However, if you're trying to debug...
# config/initializers/sidekiq.rb # Perform Sidekiq jobs immediately in development, # so you don't have to run a separate process.
Let's say you have two screens: Show a given project Show a report for all projects Ideally you want...
PDFKit converts a web page to a PDF document. It uses a Webkit engine under the hood...
Yesterday, Rails fixed a security issue (CVE-2014-3514) in Rails 4+. It was possible to use .where...
edge_rider is Power tools for ActiveRecord relations (scopes). Please note that some of the functions edge_rider provides have...
Amazing guide how to divide a ball of Javascript spaghetti distinct separate layers (model, view, controller, backend adapter).
Previously the assets group existed to avoid unintended compilation-on-demand in production. As Rails 4 doesn't behave like...
Code snippet tested with Rails 2.3 def index # ... if request.xhr? html = render_to_string(:partial => "list", :layout => false) respond_to...
Automatically builds gems from Bower packages (currently 1700 gems available). Packaged Javascript files are then automatically available in your asset...
In whenever you can schedule Ruby code directly like so: every 1.day, :at => '4:30 am' do runner "MyModel.task_to...
So you're getting an error message like the following, although your Gemfile lists shoulda-matchers and it has always...
The most obvious way to use spring is to call it explicitly: spring rails console spring rake db:migrate...
Aruba is an extension to Cucumber that helps integration-testing command line tools. When your tests involve a Rails test...