[英]Ruby on rails Edit user on Devise without entering the password
I know this question has been asked several times already and every answer leads to devise wiki, but I can't get it to work. 我知道这个问题已经被问过好几次了,每个答案都会导致设计Wiki,但是我无法使其正常工作。 I followed the wiki and some other posts here, but no luck.
我在这里关注了Wiki和其他文章,但没有运气。 I want to let the user update his info (email. username. name, etc) without having to type the password every time.
我想让用户更新他的信息(电子邮件,用户名,名称等),而不必每次都键入密码。
My registrations_controller.rb
look like this: 我的
registrations_controller.rb
看起来像这样:
class RegistrationsController < Devise::RegistrationsController
def update
# required for settings form to submit when password is left blank
if params[:user][:password].blank?
params[:user].delete("password")
params[:user].delete("password_confirmation")
end
@user = User.find(current_user.id)
if @user.update_attributes(params[:user])
# Sign in the user bypassing validation in case his password changed
sign_in @user, :bypass => true
redirect_to root_path
else
render "edit"
end
end
end
and my routes.rb
look like this: 我的
routes.rb
看起来像这样:
Sparechef::Application.routes.draw do
get "users/profile"
devise_for :users
devise_for :controllers => { :registrations => "registrations" }
resources :dashboard
root to: "home#index"
match "profile" => "users#profile"
end
I still get the message "Current password can't be blank". 我仍然收到消息“当前密码不能为空”。 If I update my routes to follow devise wiki with
devise_for :users, :controllers => { :registrations => "registrations" }
I get this error: 如果我使用
devise_for :users, :controllers => { :registrations => "registrations" }
更新路线以遵循devise_for :users, :controllers => { :registrations => "registrations" }
Wiki, devise_for :users, :controllers => { :registrations => "registrations" }
收到此错误:
Can't mass-assign protected attributes: current_password
Does anybody know how to get this to work? 有人知道如何使它工作吗?
按照上述问题注释中的attr_accessible :current_password
在User
添加attr_accessible :current_password
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.