How do I handle or prevent the "Only mail requests allowed" error in Ruby on Rails?

I have a [somewhat] calming route setup with:

map.resources :forgotten_passwords,
              :as => 'forgotten-passwords',
              :except => [:destroy, :show, :delete, :index]

      

   forgotten_passwords POST   
   /forgotten-passwords(.:format) 
   {: action => "create",: controller => "forgotten_passwords"}

   new_forgotten_password GET    
   /forgotten-passwords/new(.:format) 
   {: action => "new",: controller => "forgotten_passwords"}

   edit_forgotten_password GET    
   /forgotten-passwords/:id/edit(.:format) 
   {: action => "edit",: controller => "forgotten_passwords"}

   forgotten_password PUT    
   /forgotten-passwords/:id(.:format) 
   {: action => "update",: controller => "forgotten_passwords"}

If a visitor accesses / forgotten passwords via GET, they are presented with a blank page. However, the log shows the exception "ActionController :: MethodNotAllowed: Only mail requests allowed".

I would like to redirect to another action / view and display a nice error message to the visitor in this case. I think visitors are clicking a link in an email that cuts off the end of the url.

I understand that I could add a GET route to create and then handle the error in the controller, but something tells me what the best way is.

+2


source to share


1 answer


Explicit Disabled: The index from your routes means the password / forgotten password GET is disabled. If you remove this, you should have a valid index method again.



Inside the index method, you can create a page that explains the situation.

+5


source







All Articles