1

How can I catch the ActionView::MissingTemplate errors in Rails?

For example, my PeopleController has an Index method, but it doesn't need a template. When someone browses to root_url/people they get the default static error template.

And that's not the only controller with the issue; I want all missing template errors to redirect the user to my custom view.

  1. How to catch the exception?
  2. How to render a view afterwards?

Rails version - 3.0.19

Thanks in advance!

MrYoshiji
  • 54,334
  • 13
  • 124
  • 117
Sean Xiao
  • 606
  • 1
  • 12
  • 20

1 Answers1

6

Possible duplicate of: render default template when requested template is missing in Rails

Which says:

Use 'rescue_from' in ApplicationController:

class ApplicationController < ActionController::Base
  rescue_from ActionView::MissingTemplate do |exception|
    # use exception.path to extract the path information
    # This does not work for partials
  end
end
Community
  • 1
  • 1
MrYoshiji
  • 54,334
  • 13
  • 124
  • 117
  • cool I'll try that! Yes I read that thread before posting; the first solution is for a different version of Rails; the second is a single controller solution; and the third one i don't really like... Thanks; and looks like I didn't notice the rescue_from solution from the other thread – Sean Xiao Jan 28 '13 at 16:45