How about something like this in the controller:
def controller_method
user = User.find_by_username(params[:username])
username = user.username # raises NoMethodError when
user.nil?
rescue NoMethodError
render :file => "/path/to/404.html"
end
James
On Jan 1, 2008 5:28 AM, Will <willycheung gmail.com> wrote:
>
> Hi,
>
> I'm having trouble displaying the 404 page when an
exception occurs.
> In my controller I have
>
> user = User.find_by_username(params[:username])
>
> and in view I have
>
> <%= user.username's page %>
>
> If params[:username] is invalid or does not exist,
NoMethodError
> exception is displayed, hence 500 page in production
environment.
> However, I want this error to be 400 Page Not Found
error instead.
> How can I accomplish that? I don't want to use
redirect_to '/
> 404.html' because I want the URL to remain the same.
Any ideas?
>
> Thanks in advance.
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails" group.
To post to this group, send email to rubyonrails googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-unsubscribe googlegroups.com
For more options, visit this group at http://gro
ups.google.com/group/rubyonrails
-~----------~----~----~----~------~----~------~--~---
|