views:

33

answers:

2

I have a simple partial to show some topics from the associated community

<%= render :partial => 'shared/topic', :collection => @community.topics %>

I'm trying to make a mobile version of the site, and to not render the partial to the same view, but to a new view.

I tried something like this

def topicsCommunity
  fetch_topics ["community_id = ?", @community.id]     
  render :action => 'index'
end

But I can't get the community.id from my community view.

Also tried this :

@topicscommunity = @community.topics.find(:all, 
                     :conditions => {:community_id => @community.id})

But from the topics_Controller, it didn't work.

Thanks for the help.

+1  A: 

You don't have to use render :partial => ... in views only. You can easily do it in your controller (instead of render :action => ... or whatever).

So, just put this in the end of your controller

render :partial => 'shared/topic', :collection => @community.topics

There's no fundamental difference between calling render with :action, :partial, :text, :template or any other hash key.

Nikita Rybak
Thanks for your response.I think I didn't ask the right question. I would like to have a page like an index page of all the topics contained in the community. I thought I can do it with routes, but mysite/communities/topics/ give me always all the topics as mysite/topics/.
MAGE
A: 

If you just want to render the same template, use:

def topicsCommunity
  fetch_skills ["community_id = ?", @community.id]     
  render 'index'
end
mdrozdziel
I just updated my code (fetch_topics and not fetch_skills). But I don't understand the difference with my code. When I put a link like "topicsCommunity_topics_path" It's return a nil object from the community because it's didn't take the id as parameter.
MAGE