[Rails] ActiveRecord and options_from_collection_for_select

Anoop Ranganath anoop at ranganath.com
Sat Oct 23 04:36:17 GMT 2004


I'm using ActiveRecord to spit out a list with find_all.  In my 
template, I'm using the options_form_collection_for_select with that 
collection and when the template loads, it's performing a select for 
every object in the collection.  Needless to say, that's not the most 
desirable behaviour.

So I decided I'd give caching the results a go (it's static data), so I 
created a class variable on the ActiveRecord and wrote a method to 
lazily load the list.  It still does all the selects, and I'm guessing 
it's because ActiveRecord grabs the data each time to make sure it's 
not stale.

Any ideas how to a) get options_from_collection_for_select to grab all 
the rows at once or b) cache ActiveRecord results?

I'm absolutely floored by how fast I'm developing with Rails.  Stuff 
that would have taken me over a week in Java + WebWork2 + Velocity + 
Hibernate has taken me a little over a day with Rails.  I'm not even 
going to try to compare it to my current client's project which 
requires Struts

Anoop



More information about the Rails mailing list