Reputation: 22064
the controller file drummer.rb
and I use both old controller/action way and new resource way, either work the view file index.html.erb:
<ul>
<% @drummer_list.each do |d| %>
<li>
<%= link_to :controller => 'drummers',:action => 'show', :id => '@drummer' do %>
<%= d.first_name + ' ' + d.last_name %>
<% end %>
</li>
<% end %>
</ul>
the resource way:
<ul>
<% @drummer_list.each do |d| %>
<li>
<%= link_to drummers_path(@drummer) do %>
<%= d.first_name + ' ' + d.last_name %>
<% end %>
</li>
<% end %>
</ul>
when I click each link, in the browser url bar give me this
http://localhost:3000/drummers/@drummer
it should give me
http://localhost:3000/drummers/1
I think the problem is about the @drummer, I'm not sure about the it.
Upvotes: 0
Views: 213
Reputation: 2512
This should do it :)
<ul>
<% @drummer_list.each do |d| %>
<li>
<%= link_to "#{d.first_name} #{d.last_name}", drummers_path(d) %>
</li>
<% end %>
</ul>
Upvotes: 1
Reputation: 1725
<ul>
<% @drummer_list.each do |d| %>
<li>
<%= link_to "#{d.first_name} #{d.last_name}", d %>
</li>
<% end %>
</ul>
I would move this into a collection partial if it gets more complicated.
Upvotes: 1
Reputation: 6689
I think maybe you wanted to use "d" instead of "@drummer" as that's your loop variable of the drummer instance?
Upvotes: 1