Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么我不能在辅助方法中返回数组?
def childrenOf(a) @children = Post.find_by_parent_id(a.id) return @children end
提前致谢
你可以。
改为使用find_all_by_parent_id。
find_all_by_parent_id
而且你不需要第二行。
以下就足够了。
def childrenOf(a) @children = Post.find_all_by_parent_id(a.id) end
在 Rails 3 中,而不是使用find_all_byuse where:
find_all_by
where
def childrenOf(a) @children = Post.where(:parent_id => a.id) end