ADZ 學習筆記

Ruby/Rails, Startup, Life

Rails 筆記 - Devise Upgrade 3.1.0

| Comments

今天 bundle update 後 rails c 出現錯誤

/Users/eddie/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.1.0/lib/devise/rails/routes.rb:440:in `raise_no_secret_key': Devise.secret_key was not set. Please add the following to your Devise initializer: (RuntimeError)

config.secret_key = '6906a7107d8e7bbf5f973853d5453517eb30908575f3617f7a1fbe207910edafc5cce6bd9e77a8336bca7ee937edb7621e732696c1913b7b10ba429e74ce1ce1'

把新增加的 config.secret_key 加在 initializers/devise.rb 後,發現重設密碼和驗證信的 link 都失效了,傳來的 confirm_token 跟 database 裡面的一樣,卻無法正確驗證成功,google 了一下原來是 devise 增加 secret_key 來 encrypt reset password & confirm token,必須跟著修改 devise mailer view。

# devise/mailer/confirmation_instructions.html.erb

confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) #原來的 link 

confirmation_url(@resource, :confirmation_token => @token) #修改後的 link


# devise/mailer/reset_password_instructions.html.erb


edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) #原來的 link

edit_password_url(@resource, :reset_password_token => @token) #修改後的 link

Devise github commits:

https://github.com/plataformatec/devise/blob/2a8d0f9beeb31cd2287094c5dcf843d0bd069eb8/app/views/devise/mailer/reset_password_instructions.html.erb#L5

https://github.com/plataformatec/devise/commit/d56641f514f54da04f778b2a9b816561df7910c2

Comments

comments powered by Disqus