I have a users table. I have a journals table. users has_many :journals. journals belongs_to :user. I would like to use the auto generated user methods to get journals tied to a specific user. Example. A url like http://site.com/john/ should return all jounrals from the user who''s login is john. user = User.find_by_login(params[:login]) @journal_pages, @journals = paginate :user.journals, :per_page => 10 is what I thought would work. But it does not. I can use the user.journals in other areas but it seems to fail with paginate. I''ve fiddled with it for a while trying various things and looked through the sections on active record in the RoR book but can''t seem to get it to work. Any help would be appreciated. Thanks.
Yeah, this will work but it''s not as slick as you''d like (I had a similar issue). user = User.find_by_login(params[:login]).id @journal_pages, @journals = paginate :journals, :conditions=>["user_id ?",user], :per_page => 10 Might be a typo.... Untested but clipped from something similar. -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Nathan Hess Sent: Friday, October 28, 2005 1:59 PM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails] paginating a has_many record I have a users table. I have a journals table. users has_many :journals. journals belongs_to :user. I would like to use the auto generated user methods to get journals tied to a specific user. Example. A url like http://site.com/john/ should return all jounrals from the user who''s login is john. user = User.find_by_login(params[:login]) @journal_pages, @journals = paginate :user.journals, :per_page => 10 is what I thought would work. But it does not. I can use the user.journals in other areas but it seems to fail with paginate. I''ve fiddled with it for a while trying various things and looked through the sections on active record in the RoR book but can''t seem to get it to work. Any help would be appreciated. Thanks. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Well I can verify that does work, because that''s what I had originally :) I wanted to use the built in methods/objects instead of using the :conditions. Thanks for the help though, I''ll most likely just fall back to using that method for now. Hogan, Brian P. wrote:>Yeah, this will work but it''s not as slick as you''d like (I had a >similar issue). > > >user = User.find_by_login(params[:login]).id >@journal_pages, @journals = paginate :journals, :conditions=>["user_id >?",user], :per_page => 10 > > > > >Might be a typo.... Untested but clipped from something similar. > > > >-----Original Message----- >From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >[mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Nathan Hess >Sent: Friday, October 28, 2005 1:59 PM >To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >Subject: [Rails] paginating a has_many record > > >I have a users table. >I have a journals table. >users has_many :journals. >journals belongs_to :user. > >I would like to use the auto generated user methods to get journals tied > >to a specific user. > >Example. A url like http://site.com/john/ should return all jounrals >from the user who''s login is john. > >user = User.find_by_login(params[:login]) >@journal_pages, @journals = paginate :user.journals, :per_page => 10 > >is what I thought would work. But it does not. I can use the >user.journals in other areas but it seems to fail with paginate. > >I''ve fiddled with it for a while trying various things and looked >through the sections on active record in the RoR book but can''t seem to >get it to work. Any help would be appreciated. > >Thanks. > > > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > > >