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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
andreo-FdlSlcb4kYpknbxzx/v8hQ@public.gmane.org
2013-Mar-26 12:29 UTC
Re: Displaying Reviews on User-page
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. On Friday, 22 March 2013 19:38:45 UTC+1, Ruby-Forum.com User wrote:> > 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? > > -- > Posted via http://www.ruby-forum.com/. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/H-hnuBNyIQwJ. For more options, visit https://groups.google.com/groups/opt_out.