How can I display all records created by a user?
I have a table of users, venues and reviews where a user can have many reviews and a venue has many reviews.
How can I go about displaying all the reviews written by a user on each users show page?
I'm currently displaying the reviews written by users on the associated venue show pages using this bit of code:
<%= render :partial => 'reviews/review', :collection => @venue.reviews %>
Is it possible to reuse the review partial for this?
Using:
<%= render :partial => 'reviews/review', :collection => @user.reviews %>
in the user show page gives a undefined method `review_path' error.
Thanks for an开发者_如何学JAVAy help its much appreciated!
edit
Review partial
<div class="review">
<div class="reviewer_details">
<div class="reviewer_details_photo">
<%= image_tag review.user.avatar.url(:thumb) %>
</div>
<%= review.user.username %>
</div>
<div class="review_content">
<h2 class="review_partial_title"><%= link_to review.title, [@venue, review] %></h><br>
<p><%= review.rating %></p>
</div>
<div class="clearall"></div>
</div>
Each review
only has one venue
, right?
So try replacing link_to review.title, [@venue, review]
with
link_to review.title, [review.venue, review]
As @Devin said, @venue
is nil
in your user-directed reviews list.
When you call that partial you are not passing an @venue.
Try changing <%= link_to review.title, [@venue, review] %>
To something a little more broad like <%= link_to review.title, [object, review] %>
And in your calls to this partial use
<%= render :partial => 'reviews/review', :collection => @user.reviews, :locals => {:object => @user} %>
精彩评论