我正在使用带有Devise的Ruby on Rails 3并发送确认电子邮件。电子邮件正常工作(就发送而言)但是当我点击确认我的帐户链接时,它会产生错误 任何人都可以解释一下,或者至少指出我正确的方向是什么/如何解决这个问题?
这是我在日志中看到的错误:
Started GET "/users/confirmation?confirmation_token=qKvZWHgj6ncYAyuQq3e1" for 127.0.0.1 at 2012-08-15 20:57:11 +0300
Processing by ConfirmationsController#show as HTML
Parameters: {"confirmation_token"=>"qKvZWHgj6ncYAyuQq3e1"}
User Load (9.0ms) SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = 'qKvZWHgj6ncYAyuQq3e1' LIMIT 1
Completed 500 Internal Server Error in 35920ms
NoMethodError (undefined method `only_if_unconfirmed' for #):
app/controllers/confirmations_controller.rb:58:in `with_unconfirmed_confirmable'
app/controllers/confirmations_controller.rb:40:in `show'
Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.5/lib/action_dispatch/middleware/templates/rescues/_trace.erb (8.0ms)
Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.5/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (3.0ms)
Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.5/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (4479.3ms)
我验证了url中的令牌与db中此用户的完全匹配。
答案 0 :(得分:0)
可能你有一个非常新版本的设计,它改变了处理确认令牌的方式,所以如果用这样的设计生成视图:
rails g devise:views
然后在 app / views / devise / mailer / confirmation_instructions.html.erb 文件下,你有类似的内容:
....
<%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %>
....
你应该改变:
<%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @token) %>
如您所见,他们使用名为@token
的实例变量而不是@resource.confirmation_token
这应该可以做到!