简体   繁体   English

如何自定义设计重置密码模板?

[英]How to customize devise reset password template?

I want to use the default template to send reset password mail. 我想使用默认模板发送重置密码邮件。 I generate devise views and restart the server, but still failed with undefined method 'edit_password_url' 我生成设计视图并重新启动服务器,但是仍然失败,并带有undefined method 'edit_password_url'

reset_password_instruction.html.erb reset_password_instruction.html.erb

<p><%= t(:hello).capitalize %> <%= @resource.email %>!</p>

<p><%= t '.request_reset_link_msg' %></p>

<p><%= link_to t('.password_change_link'), edit_password_url(@resource, reset_password_token: @token, config: message['client-config'].to_s, redirect_url: message['redirect-url'].to_s).html_safe %></p>

<p><%= t '.ignore_mail_msg' %></p>
<p><%= t '.no_changes_msg' %></p>

What's wrong? 怎么了?

upd routes.rb 更新路由

mount_devise_token_auth_for 'User', at: 'users', controllers: { ... passwords: 'devise_overrides/passwords' }

I overrided devise user method send_reset_password_instructions 我重写了send_reset_password_instructions用户方法send_reset_password_instructions

def send_reset_password_instructions(opts=nil)
    token = set_reset_password_token

    opts ||= {}

    # fall back to "default" config name
    opts[:client_config] ||= "default"
    url = edit_password_url(self, reset_password_token: token, config: opts['client-config'], redirect_url: opts['redirect-url'] 

    opts[:url] = url


    # This is devise send method
    # send_devise_notification(:reset_password_instructions, token, opts)
    # This is mine
    MyMailer.forgot(opts).deliver_now
    token
  end

According to this post you can change edit_password_url to edit_password_path and pass it the necessary data. 根据这篇文章,您可以将edit_password_url更改为edit_password_path并传递必要的数据。 Let me know if this has helped. 让我知道这是否有所帮助。

If not, please provide more information such as which version of Devise you're using, how your controller looks and what the routes' output is. 如果不是,请提供更多信息,例如您使用的是哪个版本的Devise,控制器的外观以及路线的输出是什么。

I think you're missing the routes, add to your router.rb devise routes: 我认为您缺少路由,请在router.rb添加路由:

devise_for :users

PD: Please show your routes.rb in the question. PD:请在问题中显示您的routes.rb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM