ruby on rails - How redirect 'Confirmation token invalid' on Devise -
i configured rails application devise :confirmable , after registration user receives email confirmation link. when user click in link second time token invalid expected behavior in application. however, sends user page located @ "app\views\devise\confirmations\new.html.erb" error 'confirmation token invalid' , want show error(<%= devise_error_messages! %>), in sign in page. (actually, there 2 possible states: a) token expired , user not confirmed user must ask token once again; b) token expired , user confirmed user must sign in)
for this, inherited devise::confirmationscontroller creating own confirmationscontroller override show method can redirect sign in page if there error follows:
class confirmationscontroller < devise::confirmationscontroller def after_confirmation_path_for(resource_name, resource) super end def new super end def after_resending_confirmation_instructions_path_for(resource_name) super end def create super end def show self.resource = resource_class.confirm_by_token(params[:confirmation_token]) if resource.errors.empty? set_flash_message(:notice, :confirmed) if is_navigational_format? sign_in(resource_name, resource) respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) } else respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render 'devise/sessions/new' } end end end
and in routes.rb have configuration:
get "confirmations/show" devise_for :users, :path => '', :path_names => {:sign_in => 'login', :sign_out => 'logout'}, :controllers => {:confirmations => 'confirmations'} (...)
it redirects sign in page, can't pass error(s) present in resources.errors sign in page doesn't matter how hard try. how can solve problem?
btw, user model configured in way:
devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
the thing need change in confirmation_instructions.html.erb
just replace line
<p><%= link_to 'confirm account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>
with this
<p><%= link_to 'confirm account', confirmation_url(@resource, :confirmation_token => @token) %></p>
that's it.
Comments
Post a Comment