Reputation: 57
I am trying to display a particular product by clicking on it from the list
<ul>
<% products.each do |product| %>
<tr>
<a href="<%= products_path(@product) %>"><%= product.title %> . </a>
<br/>
</tr>
<% end %>
</ul>
Expected results should be products/1
but the result is products.1
and should displays a list of products
Upvotes: 1
Views: 294
Reputation: 1598
If you want to do in this way instead of
<ul>
<% products.each do |product| %>
<tr>
<a href="<%= products_path(@product) %>"><%= product.title %> . </a>
<br/>
</tr>
<% end %>
</ul>
try
<ul>
<% products.each do |product| %>
<tr>
<a href="/products/#{product.id}"><%= product.title %></a>
<br/>
</tr>
<% end %>
</ul>
but in rails way you can do
<ul>
<% products.each do |product| %>
<tr>
<%= link_to product.title, product_path(product) %>
<br/>
</tr>
<% end %>
</ul>
or
<ul>
<% products.each do |product| %>
<tr>
<%= link_to product.title, product %>
<br/>
</tr>
<% end %>
</ul>
and in routes you shoud specify
resources :products
Upvotes: 0
Reputation: 521
If your routes used resources :products , then you can use simply
No need to use any path. Just go with Product object.
Note : In controller method should be call "show".
Upvotes: 0
Reputation: 7361
Instead of this
<a href="<%= products_path(@product) %>"><%= product.title %> . </a>
Use rails standard way
<%= link_to product.title, product_path(product) %>
Upvotes: 3