2014-09-01 37 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

相關問題