如何在rails3中使用模板渲染集合? [英] How to render collection with template in rails3?

查看:34
本文介绍了如何在rails3中使用模板渲染集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果app/views/posts/中有_post.html.erb,我可以在app/views/posts/index.html中输入<%= render @posts %>.erb ,但是如果 app/views/users/posts/中的 _post.html.erb 文件,怎么写?

If there is a _post.html.erb in app/views/posts/, I can input <%= render @posts %> in app/views/posts/index.html.erb , but if the _post.html.erb file in app/views/users/posts/, how to write?

我试过 <%= render @posts, :template =>'users/posts/post' %> ,但它不起作用.

I tried <%= render @posts, :template => 'users/posts/post' %> , but it does not work.

推荐答案

<%= render :partial => 'users/posts/post', :collection => @posts %>

这篇关于如何在rails3中使用模板渲染集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆