class Book::Page end class MyBook < Book def new_page Page.new # has to be `Book::Page` in development to...
At TaskRabbit, we have gone through a few iterations on how we make our app(s). In the beginning, there...
Rails 4.0 introduced a helpful new method for ActiveRecord queries: where.not. It can make clunky queries easier to read.
A MySQL DECIMAL column is used when it is important to preserve exact precision. It takes two parameters, where...
When you do something like this in your code: def var_value @var ||= some_expensive_calculation end
If you have a FooController and also have a layout app/views/layouts/foo.html, Rails will use this without being told so.
TLDR: This card explains which threads and processes interact with each other when you run a Selenium test with Capybara...
tl;dr: Using has_many associations with a :through option can lead to lost or duplicate records. You should avoid...
On recent/fresh installations of Ruby 1.8.7 you may encounter this error why calling any bundled binary (or just bundle exec...
We've since created ActiveType which has a restricted subset of Virtus' features. It might be enough for your needs...
In Ruby, classes and modules are called constants. This card explains how Ruby resolves the meaning of a constant.
Modern IRB has time measurement built in. measure # Enable measure :off # Disable Custom Should your version of IRB not offer...
Before Rails 3.2.14, when supplying an invalid locale to I18n, it would fall back to its config.i18n.default_locale (which is...
Goal Within before_* Within after_* Cancel later callbacks throw :abort throw :abort Rollback the transaction throw :abort raise ActiveRecord::Rollback...
Ubuntu 12.04 LTS x64, Ruby 1.8.7, Rails 2.13, PDFKit 0.5.4, Phusion Passenger Apache 2 I ran into this, when I...
Whenever you create a table from a database migration, remember to add updated_at and created_at timestamps to that...
If you need to enable NewRelic monitoring on certain machines within the same Rails environment, a simple solution is to...
Ubuntu has a package mysql-sandbox that lets you install multiple MySQL versions into your user home: Install mysql-sandbox...
Rails has always included a scaffold script that generates a default controller implementation for you. Unfortunately that generated controller is...
It is good programming practice to Don't Repeat Yourself (or DRY). In Ruby on Rails we keep our code...
You might not know that Rails disables CSRF protection in tests. This means that if you accidentally forget to send...
Copy the attached file to features/support. This gets you a convenience method: Capybara.javascript_test? Is true for Selenium, capybara-webkit...
Chrome extension that shows all info from your rails log (like parameters, response times, view rendering times, DB requests) inside...
If you want to have routes that are only available in tests (e.g. for testing obscure redirects), you can use...