2014-09-01 62 views
0

我使用localhost:3000上的确认电子邮件进行注册。在我development.rb我补充这样1个错误禁止该用户保存:确认令牌无效

config.action_mailer.default_url_options = {:host => 'localhost:3000'} 
    config.action_mailer.delivery_method = :smtp 
    config.action_mailer.smtp_settings = { 
    :address => 'smtp.gmail.com', 
    :port => '587', 
    :authentication => :plain, 
    :user_name => '[email protected]', 
    :password  => 'mypassword', 
    :domain => 'localhost:3000', 
    :enable_starttls_auto => true 
} 

时,我已经注册我打开我的电子邮件,然后在收件箱中显示的消息可以确认,通过下面的链接您的帐户电子邮件:确认我的帐户我点击这个链接。它重定向到本地主机:3000 /用户/ sign_in,当我在我的收件箱中点击这个链接(确认我有分)。它再次显示错误,这样我就可以登录成功。但:

在URL

http://localhost:3000/users/confirmation?confirmation_token=dWUeHVP_N7VzsVwvkNW5

meassage错误:

Resend confirmation instructions 
1 error prohibited this user from being saved: 
Confirmation token is invalid 
在当我点击链接我的电子邮件收件箱

“确认我的帐户”再次我希望它重定向到本地主机:3000 /用户/ sign_in。如何再次点击链接“确认我的帐户”时,我如何重定向到localhost:3000/users/sign_in?请帮帮我!

+0

你在使用设计吗? – 2014-09-01 09:02:45

+0

是的,我正在使用设计 – 2014-09-01 09:05:40

回答

1

确认后confirmation_token变为零并导致此错误,您只能使用确认链接一次。如果你想重定向一个人sign_in网址,如果确认已经完成。然后你需要重写设计确认控制器。

def show 
    self.resource = resource_class.confirm_by_token(params[:confirmation_token]) 
    if resource.errors.empty? 
    set_flash_message(:notice, :confirmed) if is_flashing_format? 
    sign_in(resource_name, resource) 
    respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) } 
    else 
    redirect_to new_user_session_path 
    #respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new } 
    end 
end 
+0

现在它的工作我非常感谢你的答案。 – 2014-09-01 09:13:45

相关问题