Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 轨道4+;设计不可侵犯:重置密码_Ruby On Rails_Ruby On Rails 4_Devise_Devise Invitable - Fatal编程技术网

Ruby on rails 轨道4+;设计不可侵犯:重置密码

Ruby on rails 轨道4+;设计不可侵犯:重置密码,ruby-on-rails,ruby-on-rails-4,devise,devise-invitable,Ruby On Rails,Ruby On Rails 4,Devise,Devise Invitable,我有一个用户索引,我想添加一个按钮,当我点击它时会发送一封密码重置电子邮件(当用户失去邀请时) #查看 #控制器 def重置密码 @user=user.find(参数[:id]) email=@user.email #消防密码重置。。。 将\u重定向到用户\u路径 结束 通常Deave使用表单重置密码,但我认为我可以覆盖此表单,因为电子邮件是已知的,可以在参数中提供。您可以这样做,并使用Deave现有的方法,从文档: 唯一的问题是,它在发送电子邮件后将我注销。还有其他原因吗?我想这是因为这一行

我有一个用户索引,我想添加一个按钮,当我点击它时会发送一封密码重置电子邮件(当用户失去邀请时)

#查看
#控制器
def重置密码
@user=user.find(参数[:id])
email=@user.email
#消防密码重置。。。
将\u重定向到用户\u路径
结束

通常Deave使用表单重置密码,但我认为我可以覆盖此表单,因为电子邮件是已知的,可以在参数中提供。您可以这样做,并使用Deave现有的方法,从文档:


唯一的问题是,它在发送电子邮件后将我注销。还有其他原因吗?我想这是因为这一行:
@user.reset\u password(new\u password,new\u password)
。因为用户的密码已更改并创建新会话。您可以跳过这一行,只需使用
send\u reset\u password\u指令
。在我看来,这可能应该由管理员用户通过管理员面板完成。这是由管理员完成的,对于非当前用户
# View
<% @users.each do |user| %>
    <%= link_to "Reset Password", reset_password_path(user) %> 
<% end %>

# Controller
def reset_password
    @user = User.find(params[:id])
    email = @user.email

    # Fire password reset...

    redirect_to users_path
end
def reset_password
 #Generate random, long password that the user will never know:
 new_password = Devise.friendly_token(length = 50)

 @user = User.find(params[:id])
 @user.reset_password(new_password, new_password)

 #Send instructions so user can enter a new password:
 @user.send_reset_password_instructions

 redirect_to users_path
end