开发者

Rails 3.1 routing confusion

开发者 https://www.devze.com 2023-04-11 05:03 出处:网络
I am trying to create a link to a record in my application: <ul class=\"presentation-box\"> <% @presentations.each do |presentation| %>

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消