Category Archives: Rails

RubyTapas Episode 21: Domain Model Events

Today’s free Monday episode features a rare delving into Rails code. We take a look at a fat controller, and thin it down by identifying the model lifecycle events that are hiding inside it. This episode garnered a lot of … Continue reading

Posted in Rails, Ruby, RubyTapas Samples, Screencasts | 4 Comments

Configuring database_cleaner with Rails, RSpec, Capybara, and Selenium

How I avoid finding myself in database bizarro world while testing Rails apps. Continue reading

Posted in Rails, Ruby | Tagged , , , , , | 14 Comments

ActiveRecord Default Association Extensions

How to add helper methods to all associations of a given type, as well as to the model class. Continue reading

Posted in Rails | Tagged | 5 Comments

DRYing up your validations using DB reflection

Avoiding silent truncation of your model fields requires putting length validations on them. But this can introduce duplication of knowledge. In this post I demonstrate how to pull limit information directly from the DB into your model validations. Continue reading

Posted in Rails | Tagged , , , | 26 Comments

Your Code is My Hell

It occurred to me recently that my experience as a Rails developer may be somewhat unique. I often get brought in to help preexisting Ruby/Rails projects evolve and mature in a sustainable way. As a result, the vast majority of … Continue reading

Posted in Rails, Rants, Ruby | Tagged , , , , , | 125 Comments

View Sandboxes for Rails

Designing HTML views is an iterative, interactive process by nature. And anything that slows down the iterations, slows down development. I was working on a form recently where the steps to show it went something like this: Go to the … Continue reading

Posted in Howto, Rails | Tagged , | 14 Comments

Object Oriented Programming Comes to Rails

decent_exposure helps you program to an interface, rather than an implementation in your Rails controllers. Sharing state via instance variables in controllers promotes close coupling with views. decent_exposure gives you a declarative manner of exposing an interface to the state … Continue reading

Posted in Rails, Rants, Ruby | Tagged , , , | 5 Comments

Counters for Partials

Sometimes I like to number rows using a counter when rendering lists of things: <% @products.each_with_index do |product, i| %> <li class=”product_<%= i %>”><%= product.name %></li> <% end %> They are handy for testing, among other things. Of course, if … Continue reading

Posted in Rails, Ruby | Tagged , , , , | 2 Comments

The Trifecta of FAIL; or, how to patch Rails 2.0 for Ruby 1.8.7

It’s an oft-stated fact that most disasters result not from a single point of failure but from a combination of failures reinforcing each other. I wouldn’t term the problem I ran into last Friday a disaster, but it certainly cost … Continue reading

Posted in Rails, Rants, Ruby | Tagged , , , , , | 18 Comments