我想将密码控制器覆盖到不同的创建操作。所以我可以生成随机密码并保存用户然后将密码发送到用户电子邮件。
我喜欢这个。 的的routes.rb
devise_for :users, :controllers => { :passwords => "passwords" }
密码控制器。
class PasswordsController < Devise::PasswordsController
def create
size = 6
charset = %w{ 2 3 4 6 7 9 a v n A j C u D q E i F p G m H J K M N P Q R T V W X Y Z}
self.resource.password = (0...size).map{ charset.to_a[rand(charset.size)] }.join
if self.resource.save(:validate => false)
self.resource = resource_class.send_reset_password_instructions(resource_params)
else
#do nothing yet
end
end
end
此代码向用户发送电子邮件,但预期密码不存在。
resset_password_instructions.html.erb
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p>Your new password is <%= @resource.password %></p>
<p>Your password won't change until you access the link above and create a new one.</p>
我做错了什么?
提前致谢。