Category Archives: Rails

Rake tasks, arguments, and external scripts

I’ve previously covered how to use an external script from within a Rake task. This time, we want to be able to pass an optional argument to our task, that will be used within our external script, too.

Posted in Automation, Rails | Comments Off

Using a partial as an optional layout

Rails uses partials a lot, and you can even use partials as mini-layouts. What I wanted to do is render flashes either as a normal partial (i.e. passing a string of text to be displayed), or as a layout (passing … Continue reading

Posted in Rails | Comments Off

Rake task with an external script using ActiveRecord

Using Rake to call an external script is quite straightforward: you can simply load it, or call “system”, or “exec”. By the same token, using ActiveRecord classes in a Rake task is easy: you just need to state your task … Continue reading

Posted in Rails | Comments Off

Icon links with data-uris (no CSS sprites !)

One step in getting to a snappy website experience is reducing HTTP requests. One technique contributing to this reduction is using CSS sprites for icon links. Today, however, I’ll show you how you can achieve the same objective using data-uris. … Continue reading

Posted in Rails | Comments Off

Rails 3 in Action

Several months ago, I took a look at Rails 3 in Action by Ryan Bigg and Yehuda Katz. The publisher has since provided me with a copy of the first edition, and I’m pleased to say that while the eBook … Continue reading

Posted in Rails | Comments Off

Posting forms with AJAX on checkbox toggle

In a recent Rails 3.1 project, I wanted to have some values updated via AJAX when a checkbox value is checked or unchecked. As I was unable to find anything on the subject online, I figured I would document it … Continue reading

Posted in AJAX, CoffeeScript, jQuery, Rails | Comments Off

First encounter with the Rails asset pipeline and Coffeescript

I was working on a Rails 3.1 project, and wanted to have some javascript image preview functionality (much like this) in several places within the project. Since this project used the new Rails 3.1, I decided I’d do my best … Continue reading

Posted in CoffeeScript, jQuery, Rails | 2 Comments

Initializing the test database before a Cucumber session (in Rails)

In one of my side projects, I needed some setup data to be present in the test database before each Cucumber session. Since this took me a few moments to get right, I figured I’d document it here.

Posted in Rails, Ruby | 4 Comments

Cucumber tweaks

I’ve lately started to use Cucumber and Selenium (via Capybara) “for real” to be used as the testing mechanism on my latest Rails project. In fact, I’ve been relying on it quite heavily to test views : I skipped the … Continue reading

Posted in Rails | Comments Off

Leveraging Active Record reflections

I recently ran into an issue using the permanent records gem: when you permanently destroy a record (i.e. NOT soft delete), the dependent records with a `:dependent => :destroy` relationship are only soft deleted (i.e. marked as deleted, but kept … Continue reading

Posted in Rails, Ruby | Comments Off