Forum: Ruby on Rails collect array values

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Kyle M. (Guest)
on 2006-01-24 09:40
(Received via mailing list)
This may be more of a Ruby question, but I wasn't sure.

Is there a way to run a find on a model and then save two fields as
key => value in an array for each row. Then use this array on the
template for checking if various checkbox or select values are
checked? I'm trying to avoid running one query to check the value for
each box in the form.

- Kyle
Kelly Dwight F. (Guest)
on 2006-01-24 09:50
(Received via mailing list)
Is this what you mean?

myhash = Hash.new
Model.find(:all).collect{|m| myhash[m.value1]=m.value2}
Kyle M. (Guest)
on 2006-01-24 21:22
Thanks Kelly, that works great.

Kyle


Kelly Dwight F. wrote:
> Is this what you mean?
>
> myhash = Hash.new
> Model.find(:all).collect{|m| myhash[m.value1]=m.value2}
This topic is locked and can not be replied to.