【问题标题】:"Send me reset password instructions" not working with Devise?“向我发送重置密码说明”不适用于设计?
【发布时间】:2014-03-18 04:17:03
【问题描述】:

所以我一直在修改 Devise 视图,当我查看 Forgot Password 视图,然后点击注册的电子邮件地址并单击“向我发送重置密码说明”时,令我惊讶的是,我收到了这个:

这是服务器日志:

Started POST "/users/password" for 127.0.0.1 at 2014-03-18 00:13:14 -0400
Processing by Devise::PasswordsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"uVUzOM4xJcbJSl5uLHgV7vuXnUjw8FsBgLptoedq4cw=", "user"=>{"email"=>"andrew@gmail.com"}, "commit"=>"Send me reset password instructions"}
  User Load (0.3ms)  SELECT "users".* FROM "users" WHERE "users"."email" = 'andrew@gmail.com' ORDER BY "users"."id" ASC LIMIT 1
  User Load (0.1ms)  SELECT "users".* FROM "users" WHERE "users"."reset_password_token" = '96b5adaa30ec048962aa6cbc67c3538af1b0dd36d8aa1a929b9de6ec9b92483b' ORDER BY "users"."id" ASC LIMIT 1
   (0.1ms)  begin transaction
Binary data inserted for `string` type on column `reset_password_token`
  SQL (0.5ms)  UPDATE "users" SET "reset_password_token" = ?, "reset_password_sent_at" = ?, "updated_at" = ? WHERE "users"."id" = 1  [["reset_password_token", "96b5adaa30ec048962aa6cbc67c3538af1b0dd36d8aa1a929b9de6ec9b92483b"], ["reset_password_sent_at", Tue, 18 Mar 2014 04:13:14 UTC +00:00], ["updated_at", Tue, 18 Mar 2014 04:13:14 UTC +00:00]]
   (5.0ms)  commit transaction
  Rendered devise/mailer/reset_password_instructions.html.erb (1.5ms)
Completed 500 Internal Server Error in 57ms

ActionView::Template::Error (Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true):
    2: 
    3: <p>Someone has requested a link to change your password. You can do this through the link below.</p>
    4: 
    5: <p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @token) %></p>
    6: 
    7: <p>If you didn't request this, please ignore this email.</p>
    8: <p>Your password won't change until you access the link above and create a new one.</p>
  app/views/devise/mailer/reset_password_instructions.html.erb:5:in `_app_views_devise_mailer_reset_password_instructions_html_erb__2519734817603171421_70315561035180'

我做错了什么,我该如何解决?

【问题讨论】:

    标签: ruby-on-rails devise


    【解决方案1】:

    安装devise后告诉你至少需要复制以下内容

    config.action_mailer.default_url_options = { :host => 'localhost:3000' }
    

    致config/environments/development.rb

    为邮寄者设计需要。

    更多信息请参见https://github.com/plataformatec/devise#getting-started

    【讨论】:

    • 我正在根据控制器规范测试请求,并且恰好需要该行。谢谢
    【解决方案2】:

    Devise 需要一些额外的配置才能通过电子邮件重置密码。除了用于实际发送重置电子邮件的电子邮件帐户和密码之外,它还需要一个主机来发送电子邮件。

    http://blog.codeschool.com/post/32745236583/re-generating-forgot-password-emails-with-devise 有一个很好的教程来让重置密码电子邮件工作。

    【讨论】:

    • 不要只是过去的链接,给出解释,这将有助于Louis93理解问题。
    猜你喜欢
    • 2013-10-18
    • 1970-01-01
    • 2012-07-17
    • 1970-01-01
    • 1970-01-01
    • 2012-02-08
    • 1970-01-01
    • 1970-01-01
    • 2015-03-12
    相关资源
    最近更新 更多