Displaying Reviews on User-page

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

  • <%= link_to @game.title, review %> Posted <%= time_ago_in_words(review.created_at) %> ago you freak. <% if !current_user?(@user) %> | <%= link_to "delete", review, method: :delete, data: { confirm: "You sure?" } %> <% end %>
  • 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?

    to begin with if you use the same variable params[:id] to pass:
    @user = User.find(params[:id])
    @game = Game.find(params[:id])
    obviously you only gonna get user 1 and review, rails cant distinguish
    which model you are calling to know which id to pass, you have look at
    your
    parameters and see what you are passing.

    also you are showing the users controller, then you show a partial and
    we
    dont know how is it being called(you should post also the
    users/show.html.erb)

    and after you finish with routes for get “games/:id/reviews/:id” =>
    “reviews#show”, as: “review” , which has nothing to do with users!

    so without trying to be offend I will ask, have you read the
    documentation?
    are you a experienced developer? if not you probably should start by
    reading a good book on about how to do stuff. here they recomend a lot
    the http://ruby.railstutorial.org/ and the rails documentation, but a
    book
    like http://pragprog.com/book/rails2/agile-web-development-with-rails
    cant
    hurt!

    before you come here asking questions that leave all of us wondering
    what
    you doing exactly, reading is the best way through it. there is no
    shortcuts in life only hard work.

    This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

    | Privacy Policy | Terms of Service | Remote Ruby Jobs