dimanche 20 septembre 2015

Rescuing LoadError in Rails application

In my Rails 3 app, I am fetching path_info by:

Rails.application.routes.recognize_path(url, { :method => request.request_method }) rescue {}

If a crawler hits a URL like "http://localhost:3000/admin_", the above code raises following error:

LoadError: Expected /Users/user/myRailsApp/app/controllers/admin_controller.rb to define Admin_Controller
from /Users/user/.rvm/gems/ree-1.8.7-2012.02/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:492:in `load_missing_constant'

I have two questions:

  1. Why is rescue not working? If I change it to rescue LoadError => e, exception is handled gracefully.
  2. Is there any other alternative rather than rescuing such exception(s)?

Aucun commentaire:

Enregistrer un commentaire