Reputation: 5210
How can i redirect to some custom page if a user hits the restore password button with the email input field empty? Now i'm redirected to users/password
page. Devise doesn't provide any method to do it. Another point is that explanation message should be available(ex. "Email should not be blank.
") on the page i'm redirected to.
Upvotes: 0
Views: 1477
Reputation: 6063
You need to sub-class Devise's passwords_controller.rb
and override the create
method to do so.
In app/controllers/my_passwords_controller.rb
:
class MyPasswordsController < Devise::PasswordsController
# POST /resource/password
def create
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
if resource.errors.empty?
set_flash_message(:notice, :send_instructions) if is_navigational_format?
respond_with resource, :location => new_session_path(resource_name)
else
# Redirect to custom page instead of displaying errors
redirect_to my_custom_page_path
# respond_with_navigational(resource){ render_with_scope :new }
end
end
end
Then change your routes.rb
to tell devise to use this controller :
devise_for :users, :controllers => { :passwords => :my_passwords }
Upvotes: 2