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