I am trying to create a link to a record in my application:
<ul class="presentation-box">
<% @presentations.each do |presentation| %>
<li><%= link_to "Presentation", presentations_path(@presentation) %></li>
<li><%= presentation.author %></li>
<% end %>
</ul>
With the following line in the routes file:
resources :presentations
root :to => 'presentations#index'
For some reason, when I click the link it's taking me to the Presentation index view. I believe it should be taking me to the show view of the individual 开发者_开发问答record?
Am I missing something obvious?
Your link_to
is incorrect.
presentations_path
will actually point you to the index
, you want presentation_path(presentation)
to point directly to the resource.
Also, you can just do <%= link_to 'Presentation', presentation %>
and Rails will build the correct path for you
Change it to presentation_path(presentation)
精彩评论