在我的应用程序中,所有路径都限定为区域设置,用户选择了这样的:
scope ":locale", locale: /#{SpreeI18n::Config.supported_locales.join('|')}/ do
devise_for :users, skip: :omniauth_callbacks
get '/', to: 'homepage#index', :as => :homepage
end
如果我想发送User.find(1).send_reset_password_instructions
等重设密码说明,则会出现问题:
Devise::Mailer#reset_password_instructions: processed outbound mail in 4249.9ms
ActionView::Template::Error: No route matches {:action=>"edit", :controller=>"devise/passwords", :reset_password_token=>"-zyuNkscVkwFn2awdm27"} missing required keys: [:locale]
如何传递区域设置以便我可以发送重置令牌?
答案 0 :(得分:1)
让我们为password
:
自定义 routes.rb
scope ":locale", locale: /#{SpreeI18n::Config.supported_locales.join('|')}/ do
devise_for :users, skip: :omniauth_callbacks, controllers: { passwords: 'my_passwords' }
get '/', to: 'homepage#index', :as => :homepage
end
<强> my_passwords_controller.rb 强>
class MyPasswordsController < Devise::PasswordsController
def create
resource_params.merge!(locale: 'en') # use 'en' for eg
super
end
end
然后send_reset_password_instructions
功能会在发送电子邮件时自定义resource_params
。
请参阅devise sourcecode以了解设计的详细信息!