Tag Archives: butt biter

Butt Biter: Rails ‘truncate’ Method Broken in Ruby 1.8.7

This one threw me for far too many minutes. InĀ ActionView::Helpers::TextHelper the truncate method is broken for Ruby 1.8.7. I’m not exactly sure the version of ruby that it stopped working for, but I was previously on 1.8.6, and I don’t recall it not working. But after I upgraded to the latest patchlevel of 1.8.7, truncate stopped working.

Update 12/2/08: Fixed in Rails 2.2! (read more)

The error that I received was thus:

ActionView::TemplateError (undefined method `length' for #) on line #83 of dashboard/index.html.erb:

Fortunately, someone has submitted a ticket to Rails core. I hope it’s applied in the Rails 2.2.0 release.

Continue reading

Posted in Rails. Tagged with , .

Butt Biter: Fix State Abbreviations && Large Data Set Updates

Ran into a little butt biter today… I imported a few thousand addresses that had the state in long form, like ‘Arizona’. But I commonly used the us_states plugin for popup selection of states. Well, us_states will be looking for state abbreviations, like ‘AZ’ when it selects it’s selected value. So what’s a girl (or dude) to do? You gotta convert them states!

But there are a few concerns:

  • you need to iterate over a large set of records, maybe an entire table
  • there may be memory issues with loading such a large set

The following rake task demonstrates a technique that is more memory efficient than loading the entire model/attributes (table/fields) into memory. Only load the ‘id’ and ‘state’ attributes when you need to find your initial record set. The ‘id’ will be used to find the record for updating, and the state is need to find the new abbreviation.

Continue reading

Posted in Rails. Tagged with , , .