Declare different CSS background-images for different locales
If you would like to use language specific layout (e.g. background-images) in your applications stylesheets you can achieve this...
Login forms: Disable browser prompt to remember the password
In order to prevent the browser from asking whether to remember the password, give a form an autocomplete attribute with...
Large forms are slow on the iPad
Forms with many inputs (600+ in my case) become extremely unresponsive on an iPad, up to the point where it...
Multi-line Ruby block in Haml
There are several options, but most of them are impractical. The best way is to use the :ruby filter:
How to use html_safe correctly
Back in the war, Rails developers had to manually HTML-escape user-supplied text before it was rendered in a...
Micro clearfix mixin for Sass
Clearfix is a hack to clear floating elements without additional HTML markup. If you only need to support IE8 and...
Stub methods on any instance of a class in Rspec 1 and Rspec 2
RSpec 1 (Rails 2) With the most recent spec_candy.rb helpers you can say: User.stub_any_instance(:foo => :bar) user = User.new...
Fix multiple CKEditor instances using jQuery adapter - fixed since 4.2
Using the jQuery adapter breaks the built-in save function of CKEditor. Phenomenon: The page is submitted correctly, but the...
How to change the order of nested forms being rendered (especially blank forms)
Generally for nested forms, a blank form is placed below all other existing object forms. If you would like to...
Making the rails 3.1. asset pipeline and asset precompiling work in production mode
Recently, we had an interesting lunch-break with the rails 3.1. asset-pipeline in production mode. Daniel Zahn made a...
Test that a form field has an error with Cucumber and Capybara
You can use the step definition below to say this: Then the "Last name" field should have an error
Using heredoc for prettier Ruby code
You can use heredoc to avoid endlessly long lines of code that nobody can read. Heredoc strings preserve linebreaks and...
Rendering a custom 404 page in Rails 2
Simple: Tell the application controller how to handle exceptions, here a RecordNotFound error. Do this with the following line: # application_controller.rb...
Let a Rails 3 application make a request to itself
Ever wondered how Rails talks to itself in a Cucumber feature? In Rails 3 you can do it like this...
When Rails no longer renders changes in view templates or Sass stylesheets
Do you have page caching enabled for the development environment and there are cached pages lying around in public/?
Fix: "undefined method `bytesize' for #<Array>"
I believe that when WEBrick has trouble bringing up your Rails application, the WEBrick component that is supposed to print...
How to use Rails URL helpers in any Ruby class
If you have any class which requires access to some path methods generated by your routes. Even though you could...
Invoices: How to properly round and calculate totals
While it might seem trivial to implement an invoice that sums up items and shows net, gross and vat totals...
Always show all form errors during development
You've been there: A form cannot be submitted, but you don't see a validation error because the field...
Distance of time in what you like: days, months, years
Sometimes the Rails helper #distance_of_time_in_words is using too much magic. When you need a time difference...
How to make a single check box (or image, etc) align vertically
Consider this HTML: Even though the surrounding container defines a line-height, which vertically centers its inline elements, the check...
Ruby GetText will eval scripts containing ActiveRecord classes
When the Ruby parser module of Ruby-GetText comes across a file in one of its search directories (e.g. lib/scripts...
Detect the current Rails environment from JavaScript or CSS
Detecting if a Javascript is running under Selenium WebDriver is super-painful. It's much easier to detect the current...
How to stub class constants in RSpec
Hint: There's another card with this helper for Cucumber features. Sometimes you feel like you need to stub some...