开发者

How can I display a view inside a view from another controller?

I have 2 contr开发者_JAVA技巧ollers: articles and comments. For each articles I need to display comments.

Both of them work fine on their own, but how can I get the comments/index inside the controller/show without messing everything up ?


In your show view you would do something like this (assuming you have a app/view/comments view folder and a _comment.html.erb inside):

render :partial => 'comments/comment', :collection => @articles.comments


You can make each comment render as a partial. So, from your comments index page, just render partial on all of the comments.

Then, from your articles show page, render the comments partial for the comments related to that article.

Take a look at using partials in Rails.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜