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.
5dd60445347fc3dec62474cc732fef0d?d=identicon&s=25 Kyle Mathews (Guest)
on 2006-01-24 08: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
6559f9b9607a89074ea5e238d31ffbc2?d=identicon&s=25 Kelly Dwight Felkins (Guest)
on 2006-01-24 08:50
(Received via mailing list)
Is this what you mean?

myhash = Hash.new
Model.find(:all).collect{|m| myhash[m.value1]=m.value2}
5dd60445347fc3dec62474cc732fef0d?d=identicon&s=25 Kyle Mathews (kylemathews)
on 2006-01-24 20:22
Thanks Kelly, that works great.

Kyle


Kelly Dwight Felkins 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.