views:

161

answers:

2

Hi, I currently have the following for-loop. This is in the 'view/vendor/show.html'.

I set up a 'vendor :has_many :reviews' and this is the for-loop:

<% for review in @vendor.reviews %>

 <%= review.user_id %>
 <%= review.summary %><br />

 <%= link_to 'More', @review%>

 <hr class="left span-5" />

<% end %>

For the link_to I would like it to link to the URL: reviews/:review_id

thanks!

A: 
<%= link_to "More", review_path(@review) %>
Brian
Hi, thanks -- I get an error:review_url failed to generate from {:action=>"show", :controller=>"reviews", :id=>nil}, expected: {:controller=>"reviews", :action=>"show"}, diff: {:id=>nil}
Angela
I think I got it to work, thanks....in what situations would @review work and not work? I needed to use review.id instead.
Angela
+1  A: 

Your code right now wouldn't work,

link_to 'More', @review

you want just review (without the @) @review is not defined anywhere in your code.

Assuming you have your routes set up properly,

link_to 'More', review

should suffice. Of course Brian's code does the same thing (again, without the @ though). Rails can automatically figure out the proper path if you just use the object directly (using polymorphic routes) or with brian's:

link_to 'More', review_path(review)

Is the same as review_path(review.id) Rails automatically takes the id of the object being referenced

brad
Yeah, this is right, I stole the @review from her code, and I didn't even notice that it was review, and not @review. Good catch.
Brian