Linked content

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 blogpost about our journey, precompiling assets, fingerprinting, Haml, Sass & Compass and what he calls "the dark heinous hutch".

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


Then /^the "([^\"]*)" field should( not)? have an error$/ do |field, negate|
  expectation = negate ? :should_not : :should
  page.send(expectation, have_css('.field_with_errors', :text => field))
Linked content

Prevent the selenium webbrowser window from closing after a failed @javascript step

When cucumber encounters a failing step in a @javascript feature, the selenium browser window instantly closes. Sometimes you do not want that, because you need to see what is going on. You can click through the data your feature created, when you add the following file to your features/support directory:


After('@leave_the_window_open') do |scenario|
  if scenario.respond_to?(:status) && scenario.status == :failed
    print "Step Failed. Press return to close browser"

How to fix: Gems are unavailable although they are installed

  • If Rails or Rake are complaining about a missing gem that is listed in your Gemfile.lock and the listed version is properly installed, something is seriously wrong and needs to be fixed.
  • If you accidently executed bundle install some_gem although you wanted bundle update some_gem

What is wrong

Let's say your Gemfile asks for some-gem which you can see when running gem list but bundle show some-gem just gives you an error:

Could not find gem 'some-gem', in any of the sources

Another indicator: Doing a `…

Linked content

The Skinny on CSS Attribute Selectors

Good guide to different ways you can write CSS selectors that select elements by their attribute values.

Make an HTTP request to a machine but fake the hostname

Consider you have a website vhost listening to, redirecting all incoming requests that do not talk about the configured hostname (this is often used to redirect users to when entering only

If you want to make a request to that site's web server without actually talking to (e.g. because this is a load balancer's address but you want to access one specific machine), you cannot just request or localhost as the above vhost will redirect…

Linked content

Accept or deny JavaScript confirmation dialogs in Capybara/Selenium

These methods are available to you:

page.driver.browser.switch_to.alert.text # the confirmation text

Spreewald gives you steps like these:

When I confirm the browser dialog
When I cancel the browser dialog

Also see Type text into Javascript prompt dialogs in Capybara/Selenium.

Render custom 404 page in Rails 2


Tell the application controller how to handle exceptions, here a RecordNotFound error.
Do this with the following line:

rescue_from ActiveRecord::RecordNotFound, :with => :render_404

This will call the method render_404 whenever a RecordNotFound error occurs (you could pass a lambda instead of a symbol, too).
Now write this method:

def render_404
  render 'errors/404', :status => '404'

Finally create a 404 document views/errors/errors.html.haml.

%h1 Record Not Found

.error The record ...

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/?

Random list of ActiveSupport goodies

I recently browsed through the ActiveSupport code and found some nice stuff I did not know about:

ActiveRecord-like callbacks, if you need callbacks in non ActiveRecord objects
encrypt and decrypt ruby objects


How to make a single check box (or image, etc) align vertically

Consider this HTML:

<div style="line-height: 42px">
  <input type="checkbox" />

Even though the surrounding container defines a line-height, which vertically centers its inline elements, the check box will be top aligned if it is the only element inside the container.

It will be aligned correctly if the HTML looks like this:

<div style="line-height: 42px">
  <input type="checkbox" /> foo

Complex explanation here.

So the ac…

Solve issues with Samsung TV as computer screen

We have a big flat screen TV (Samsung LE46c650l1kxxu) in our conference room. Configuring it properly, we were encountering some issues.
This is a list of issues, providing a solution to each.

No sound with DVI/HDMI and separate audio
There are some inputs on the side of the TV. These will not work for split video and audio.
On the back are more inputs you might not have seen. Choose HDMI/DVI as video in and Audio in for HDMI/DVI as audio in. Do not use RCA audio input but the [T…

Thunderbird: Confirm encryption absence/presence before sending an e-mail

To avoid sending e-mails containing sensitive data unencrypted I strongly suggest you enable a confirmation dialog.

Enigmail can show if the e-mail being sent will be encrypted or not – and if, which keys will be used. This applies to both clicking the "Send" button or pressing Ctrl+Enter. Thus, you may disable the confirmation for the keyboard shortcut as you get a message box anyways which will avoid sending e-mails by accident.


Head over to the Enigmail preferences from the "OpenPGP" menu and tick the corresponding che…

Always store your Paperclip attachments in a separate folder per environment

tl;dr: Always have your attachment path start with :rails_root/storage/#{Rails.env}#{ENV['RAILS_TEST_NUMBER']}/.

The directory where you save your Paperclip attachments should not look like this:


The problem with this is that multiple environments (at least development and test) will share the same directory structure. This will cause you pain eventually. Files will get overwritten and…

Insert multiple blank rows into an Calc spreadsheet

Select as many rows as you'd like to insert by dragging over the row numbers on the left. Then right-click on any selected row number and select "Insert Rows". Calc will now insert multiple blank rows.

The inserted rows will copy the style from the row above the selection.

This is horrible.

Linked content

Cross-Origin Resource Sharing - Wikipedia

Cross-Origin Resource Sharing (CORS) is a browser technology specification, which defines ways for a web service to provide interfaces for sandboxed scripts coming from a different domain under same origin policy. CORS is a modern alternative to the JSONP pattern. While JSONP supports only the GET request method, CORS also supports other types of HTTP requests. Using CORS enables a web programmer to use regular XMLHttpRequest which supports better error handling than JSONP. On the other hand, JSONP works on legacy browsers that do not have C…

Hide your Selenium browser window with a VNC server

This is now part of geordi. Please don't follow the instructions below, if you use geordi.

Inspired by the recent headless Selenium note, I found yet another solution for the problem to hide your selenium tests away.

This has the advantages

  • not to require a gem (so you do not force this on others)
  • to allow you to take a look at the running webdriver if necessary

Simply make a script th…

Firefox 3.6 truncates long tables when printing

Possible fixes:

  • Upgrade your Firefox. It's fixed in 5.0.
  • Hunt down funny float or overflow directives in your CSS.
  • Remove <h1> and <caption> tags in proximity of your table (seriously).
This website uses cookies to improve usability and analyze traffic.
Accept or learn more