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 %>
精彩评论