Hello there, On my site I have a list of users, each of which can post status updates on their profile. Each user can search for other users and view their profiles too. The odd thing is, if I log in and out of each user and look at their status, their posts are specific to them (which is what i want) However...... If I search for a user and click to view their profile, it seems to display the posts of the logged in user which is what i dont want. Below is the show method which is what the profile page uses. I have tried limiting it to 1 post for a user, and also tried to set the initial param before the find to try and get around the issue. Unfortunately these didn''t work.. def show username = params[:username] @user = User.find_by_username(username) if @user @title = "Profile page of: #{username}" @info = @user.info ||= Info.new @posts = Post.find_by_user_id( session[:user_id], :order => "created_at DESC") respond_to do |format| format.html end else flash[:notice] = "No user #{username} found!" redirect_to :action => "index" end end Can anyone see why a: It displays the users status updates correctly when i''m logged in as each user and b: why the posts seem to stay as per the logged in user when i click on another user''s profile?? Any suggestions, or ways round this appreciated. Thanks for reading. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
** RESOLVED ** If anyone else experiences something like this, Original line of code: @posts = Post.find_by_user_id( session [:user_id], :order => "created_at DESC") change it to: @posts = Post.find_by_user_id( @user.id, :limit => 1, :order => "created_at desc") On 28 Nov, 19:57, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hello there, > > On my site I have a list of users, each of which can post status > updates on their profile. Each user can search for other users and > view their profiles too. > > The odd thing is, if I log in and out of each user and look at their > status, their posts are specific to them (which is what i want) > However...... If I search for a user and click to view their profile, > it seems to display the posts of the logged in user which is what i > dont want. > > Below is the show method which is what the profile page uses. > I have tried limiting it to 1 post for a user, and also tried to set > the initial param before the find to try and get around the issue. > Unfortunately these didn''t work.. > > def show > username = params[:username] > @user = User.find_by_username(username) > if @user > @title = "Profile page of: #{username}" > @info = @user.info ||= Info.new > @posts = Post.find_by_user_id( session[:user_id], :order => > "created_at DESC") > respond_to do |format| > format.html > end > else > flash[:notice] = "No user #{username} found!" > redirect_to :action => "index" > end > end > Can anyone see why a: It displays the users status updates correctly > when i''m logged in as each user and b: why the posts seem to stay as > per the logged in user when i click on another user''s profile?? > > Any suggestions, or ways round this appreciated. > > Thanks for reading.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Nov 28, 3:11 pm, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> ** RESOLVED ** > > If anyone else experiences something like this, > > Original line of code: @posts = Post.find_by_user_id( session > [:user_id], :order => "created_at DESC") > > change it to: > > @posts = Post.find_by_user_id( @user.id, :limit => 1, :order => > "created_at desc")Note that the preferred way to do this is from the other side of the association: @user.posts.find(:first, :order => ''created_at DESC'') or even to define a ''recent'' scope on Post: named_scope :recent, :order => ''created_at DESC'' and then the line in the controller reduces to: @post = @user.posts.recent.first --Matt Jones -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.