On Apr 17, 6:26 am, Nathan Domier <li...@ruby-forum.com> 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@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to