I realize the title probably doesn''t make much sense, but that was the best short description I could come up with. Anyway, I have users and pages in my site, and was using the following code in the users controller, which works fine: <code> def show @user = User.find(params[:id]) @title = @user.Fname + " " + @user.Lname en </code> However, if I go to the pages controller, and use the following code, I get "Couldn''t find user without an id" for an error. <code> def home @title = "Home" @user = User.find(params[:id]) end </code> Using User.find(1) works just fine instead of User.find(params[:id]) I feel like I''m probably just restricting something to Users only somehow, but can''t figure it out. Seems like it would be obvious to someone more experienced, (I hope?) -- 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 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.
On Apr 17, 6:26 am, Nathan Domier <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I realize the title probably doesn''t make much sense, but that was the > best short description I could come up with. > > Anyway, I have users and pages in my site, and was using the following > code in the users controller, which works fine: > > <code> > def show > @user = User.find(params[:id]) > @title = @user.Fname + " " + @user.Lname > en > </code> > > However, if I go to the pages controller, and use the following code, I > get "Couldn''t find user without an id" for an error. > > <code> > def home > @title = "Home" > @user = User.find(params[:id]) > end > </code> > > Using User.find(1) works just fine instead of User.find(params[:id]) > > I feel like I''m probably just restricting something to Users only > somehow, but can''t figure it out. Seems like it would be obvious to > someone more experienced, (I hope?)Your show action will usually be supplied with a :id parameter (since show usually means show me this particular user) via the url (eg / users/123) or query parameters. On the other hand it sounds like when you link to your home action in the pages controller you''re not supplying an id parameter, and so params[:id] is nil, so User.find(params[:id]) can''t work. Which user did you want to show? Fred> > -- > Posted viahttp://www.ruby-forum.com/.-- 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.
I wanted to pass it the id of the logged in user. I have some things that I want to show up for some users and not for others. I wanted to use @user.admin? for this, which works fine on the users pages. however, since I can''t get the @user assignment to work for pages this isn''t working either :( -- 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 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.
Aha! I''ve figured it out. In case anyone else is wondering, I have a current_user defined in sessions helper, so, I had to include sessionshelper, and set @user = current_user! -- 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 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.
Phil On Sun, Apr 17, 2011 at 8:47 PM, Nathan Domier <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Aha! I''ve figured it out. > > In case anyone else is wondering, I have a current_user defined in > sessions helper, so, I had to include sessionshelper, and set @user > current_user! >Just in case it helps; if you have a current_user helper, you don''t need to assign anything to @user in a controller at all. You can just use current_user in your view. :-)> > -- > 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 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. > >-- 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.