hey there! I'm looking for a way to display a list of Reviews written by a user on his user page.
I'm developing a game database, where users can register, create new game entries, rate them AND leave a review. (a list of reviews shall be displayed on the games show page with the users' names and a list of all reviews by a certain user shall be displayed on his show page with the games' names)
my Models should be fine so far...the review model got the foreign keys game_id and user_id, and all relationships are set: review belongs_to :game review belongs_to :user game has_many :reviews user has_many :reviews
Right now I'm having the issue, that on my user page, all his reviews are being displayed BUT as a object-name (link name the review belongs to) only the name of a game gets displayed, that's equal to the displayed user's id.
so the user with the id=1 only has review links with the name of the game with id=1, even though there are acually different games...
my show mehtod in my users_controller looks like this: def show @user = User.find(params[:id]) @reviews = @user.reviews.paginate(page: params[:page]) @game = Game.find(params[:id]) end
The partial for displaying the gamelinks looks as follows <li> <%= link_to @game.title, review %> <span class="timestamp"> Posted <%= time_ago_in_words(review.created_at) %> ago you freak. </span> <% if !current_user?(@user) %> > <%= link_to "delete", review, method: :delete, data: { confirm: "You sure?" } %> <% end %> </li>
and this is my routing resources :reviews, only: [:create, :destroy, :show]
get "games/:id/reviews/:id" => "reviews#show", as: "review"
This probably isn't right either, because right now a certain review can be accessed regardless, what the first id in the url is...
can you guys help me out?