2011-10-05 66 views
0

我想创建我的应用程序链接到一个记录:的Rails 3.1的路由混乱

<ul class="presentation-box"> 
    <% @presentations.each do |presentation| %> 
    <li><%= link_to "Presentation", presentations_path(@presentation) %></li> 
    <li><%= presentation.author %></li> 
    <% end %> 
</ul> 

随着路由文件中的以下行:

resources :presentations 
root :to => 'presentations#index' 

出于某种原因,当我点击它将我带到演示文稿索引视图的链接。我相信它应该把我带到个人唱片的节目视角?

我错过了一些明显的东西吗?

回答

1

link_to不正确。

presentations_path实际上会将您指向index,您希望presentation_path(presentation)直接指向资源。

而且,你可以做<%= link_to 'Presentation', presentation %>和Rails会为您构建

+0

随着较短的版本是有可能把演示录像标题替代字介绍的正确路径? – dannymcc

+0

是,'<%= link_to @ presentation.title,@presentation%>'。第一个参数是将显示的文本,第二个参数是资源,哪些导轨会转换为您的路径。 –

+0

太好了,谢谢! – dannymcc

1

将其更改为presentation_path(presentation)