开发者

Rails show views from a different controller

In my Ruby on Rails application

I have a page Aboutus - This has a Controller and View. Has no model.

I have a Comments model (generated by the rails generate scaffold comment) - This has a Controller, view, model

On my Aboutus pa开发者_高级运维ge, I want to show the "Comments" from the comments model, so I am thinking of using the Comments index action (to list comments) and new action (to create new comments) on my Aboutus page.

I am having trouble getting this right.

This is what I did: Aboutus controller, I added

redirect_to :controller => "comments", :action => "index"

Aboutus views, I added

<%= render 'comments/index' %>

It doesnt work, gives me Undefined redirect_to and nil object @comments errors. Could you advise me

1. A proper way to do this

2. Syntax

3. Any thing to do to config.rb ?


you want to create a partial that you use to render the comments in the comments index view, and also in your view for the aboutus page

# in about_us and in 'comments#index'
<%= render :partial 'path/to/_partial' %>

#in the about_us controller, or whatever controller dispatches the about us view

@comments = Comment.all.where(:my_conditions)

#partial view

<% @comments.each do |comment| %>
..
<% end %>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜