Search code examples
ruby-on-railsrubyruby-on-rails-3ruby-on-rails-3.1rubygems

How do I correctly handle redirects for bad url's to custom 404 page in ruby on rails?


Users can access others users profiles like this:

site.com/username

My find method in my users controller will find the user by their username.. now if the user doesn't exist I want them re-directed to a custom 404 error page I'll make.

I also want them re-directed for any other non-existant url's they type in.

I've found some solutions on google but wondering if someone can give me an up to date example of doing this in rails 3.2 as theses tutorials I've found are pre rails 3.1.

Kind regards


Solution

  • In production an ActiveRecord::RecordNotFound exception will automatically render your public/404.html file.