2010-09-18 78 views
0

我有一个简单的部分,从相关的社会表现出一定的主题使用部分来呈现一个完整的视图

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

我试图使网站的移动版本,并没有呈现偏相同的看法,但以一种新的观点。

我想是这样的

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

但我无法从我的社区鉴于community.id。

也试过这样:

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

但从topics_Controller,它没有工作。

感谢您的帮助。

回答

1

你不必只在视图使用render :partial => ...。你可以很容易地在你的控制器中执行它(而不是或其他)。

所以,只要把这个在你的控制器

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

结束还有调用render:action:partial:text:template或任何其他哈希键之间没有根本的区别。

+0

感谢您的response.I觉得我没有问正确的问题。我希望有一个像社区中包含的所有主题的索引页面的页面。我认为我可以通过路线来完成,但是mysite/communities/topics /总是给我所有主题作为mysite/topics /。 – Rufilix 2010-09-18 18:15:28

0

如果你只是想呈现相同的模板,使用方法:

def topicsCommunity 
    fetch_skills ["community_id = ?", @community.id]  
    render 'index' 
end 
+0

我刚刚更新了我的代码(fetch_topics而不是fetch_skills)。但我不明白与我的代码的区别。当我放置一个像“topicsCommunity_topics_path”这样的链接时,它会从社区中返回一个零对象,因为它没有将id作为参数。 – Rufilix 2010-09-18 18:36:32