0

I've implemented a tagging system into my app so that posts can have different tags applied to them. I am rendering the posts with a certain tag like this

 <% my_posts = post.find_by_tag("sports") %>
   <%= my_posts.each do |post| %>
   <%= post.title %><br />
   <%= post.body %><br />
 <% end %>

the only problem is that it will only render in my _post.html.erb partial or in my show.html.erb

when I try to create another partial for instance like _fact.html.erb it does not render

This is the posts controller for the page that it does work on

   def newest
     @posts = Post.paginate(:page => params[:page], :per_page => 10)
     @title = "Newest"
     @vote = Vote.new(params[:vote])

     respond_to do |format|
       format.html
       format.json { render :json => @users }
     end
   end

and in the newest view I just did a <% render :partial => @posts %>

I wanted to do the same thing except with def sports and a view that is sports.html.erb but for some reason when I do that and use another partial besides @posts it doesn't work. I've already added a line in the def sports for @facts so thats not it but I'm not sure what the problem could be.

Still new to programming so any help would be greatly appreciated, thank you.

Michael Peralta
  • 293
  • 5
  • 18

1 Answers1

0

Rails appears to do a certain amount of magic when you tell it render a collection, but, being naturally distrustful of magic, I prefer to specify the partial and use the :collection option, as I describe in answer to this question: How to render collection with template in rails3?

In your case, assuming you have a _fact.html.erb partial in views/things/, presumably you want to do something like this:

<%= render :partial => 'things/fact', :collection => @facts %>
Community
  • 1
  • 1
MrTheWalrus
  • 9,670
  • 2
  • 42
  • 66