How can I create an array from two models that have different keys in a
Rails 3.2 app?
I want to combine the results of two tables into one array so that I can
sort the array on the term alphabetically.
In my controller:
@defs = []
definitions = Definition.all
definitions.each do |d|
... # set the value of @term and @definition based on conditions
@defs << {:term => @term, :definition => @definition}
end
definitions = Definition2.all
definitions.each do |d|
... # set the value of @term and @definition based on conditions
@defs << {:term => @term, :definition => @definition}
end
Then I was hoping to display each item in the view:
@defs.each do |d|
...
<%= d.term %>
<%= d.definition %>
...
end
But I get the following error.
undefined method `definition' for #<Hash:0x007fb0cf109118>
Thanks for your help.
No comments:
Post a Comment