简体   繁体   中英

Rails 4 controller action, Rescue block not working as expected?

Why doesn't this work?? I expect the rescue block to be executed if an ActionView::TemplateError is raised. But that isn't happening for some reason...

The following is a controller action in a rails 4 app.

  def categorized
    #ActionView::TemplateError raising code
  rescue ActionView::TemplateError
    binding.pry
  end

how about if move exception in application_controller.rb:

rescue_from ActionView::TemplateError do | exception |
  binding.pry
end

Try with

rescue => e
 bindig.pry

After you that you can check error class with e.class, to make sure you are catching good exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM