Yes but, it will never reach "unless." The system fails after @user =
User.find(1) since Active Record is trying to find a record that does
not exists

On Sep 5, 7:28 pm, Ugis Ozols <[email protected]> wrote:
> One of the solutions would be to use redirect_to and flash[:notice]
> like:
>
> @user = User.find(1)
> unless @user
>   flash[:notice] = "can't find user with given id"
>   redirect_to users_path
> end
>
> I won't say it's the best but it's still a solution :)
>
> On 5 sept., 13:55, Christian Fazzini <[email protected]>
> wrote:
>
> > When navigating to:http://localhost:3000/users/12
>
> > Whats a good way of avoiding the error: "Couldn't find User with
> > ID=12", which happens when i try to display a page of user_id 12 that
> > doesnt exist in the database.
>
> > Instead of showing the error. id like to show a page that says: "This
> > user does not exist"
>
> > Someone suggested using rescue_from. Is this the best solution for
> > this? Or are there better alternative approaches?

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to