0

我正在使用带有 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 中的令牌与数据库中的该用户完全匹配。

4

1 回答 1

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

这应该够了吧!

于 2015-01-03T01:26:57.737 回答