rails中如何给局部模板传多个object

rails中如何给局部模板传多个object?

superxielei ,dearsuper问的是没有问题的,我也时候也有这个想法呢!

要传多个object的话,可是使用:locals,它是一个hash,所以你想传几个object就传几个.

[code="ruby"]
render(:partial => “example”,:locals => { :user1 => @userA,:user2 => @userB} )

在_example.html.erb中,可以直接用变量user1和user2
[/code]

如果dearsuper你想问的是如果传一个集合到局部模板,比如,传@comments给_comments.html.erb,那么可以使用:collection => @comments

[code="ruby"]<%= render(:partial => "comments.html.erb", :collection => @post.comments) %> [/code]

希望能对你有帮助.

为什么要传多个呢?本身业务逻辑有问题吧.