Collect array values


#1

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

#2

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}


#3

Is this what you mean?

myhash = Hash.new
Model.find(:all).collect{|m| myhash[m.value1]=m.value2}