采纳的答案
2008-07-24 qichunren (资深程序员)
superxielei ,dearsuper问的是没有问题的,我也时候也有这个想法呢!
要传多个object的话,可是使用:locals,它是一个hash,所以你想传几个object就传几个.
如果dearsuper你想问的是如果传一个集合到局部模板,比如,传@comments给_comments.html.erb,那么可以使用:collection => @comments
希望能对你有帮助.
要传多个object的话,可是使用:locals,它是一个hash,所以你想传几个object就传几个.
render(:partial => “example”,:locals => { :user1 => @userA,:user2 => @userB} )
在_example.html.erb中,可以直接用变量user1和user2
如果dearsuper你想问的是如果传一个集合到局部模板,比如,传@comments给_comments.html.erb,那么可以使用:collection => @comments
<%= render(:partial => "comments.html.erb", :collection => @post.comments) %>
希望能对你有帮助.
提问者对于答案的评价:
是qichunren讲的这样,要的就是locals!
其他回答
为什么要传多个呢?本身业务逻辑有问题吧.
superxielei (初级程序员) 2008-07-24




