Is it possible to show different error pages based on the controller?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For Rails < 3.0.
Yes, it is possible. I use this method in my application controller to render 404 message:
So, the only thing you need to do is to write this method for each controller, or you can change
renderline to something like this:and add method:
Then you only need to write
error_pagemethod in each controller, where you want to change default error page.EDIT:
Ups, I’ve just noticed that this method is deprecated in Rails 3. So there should be another way of doing it.
For Rails >=3.0:
Here is one example solution for this. Just add:
and add
render_404method:Or if you want to add
404.html.erbview for each controller without modifing controllers code, you can write it like this:I think it should look for this error file inside current controller’s view directory. I didn’t check it, but I think it should work. But remember to include
404.html.erbfile in each controller’s view directory. Otherwise there could be an error.