【发布时间】:2011-01-14 07:35:37
【问题描述】:
我正在尝试进一步了解 ruby .....
如果我有一个对象
@Trees = Tree.find( :all )
然后创建一个循环,为我找到的每棵树添加一些苹果...
for tree in @trees
@apples = Apple.where(:tree_location = > tree.id )
end
如何将循环的每次迭代中找到的额外苹果添加到初始对象@apples?
我试过了
@apples = @apples + Apple.where(:tree_location = > tree.id )
但收到错误“无法将 Apple 转换为数组”
感谢您的帮助....
【问题讨论】:
标签: ruby ruby-on-rails-3 for-loop