我想将两个表的结果组合到一个数组中,以便我可以按字母顺序对数组进行排序。
在我的控制器中:
@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
然后我希望在视图中显示每个项目:
@defs.each do |d|
...
<%= d.term %>
<%= d.definition %>
...
end
但我收到以下错误。
undefined method `definition' for #<Hash:0x007fb0cf109118>
谢谢你的帮助。