2011-10-05 55 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)