2011-08-11 1 views
2

을 current_password 왜 이런 일이유증 : 대량 할당 보호 할 수 없습니다 속성 :</p> <p>여기에 로그 출력이된다, 나는 사용자가 자신의 암호를 변경할 수 있도록하려면 3 +가 고안 레일

def password_update 

    @user = current_user 

    if @user.update_attributes(params[:user]) 
     flash[:notice] = 'Password Updated' 
     redirect_to '/settings/account' 
    else 
     flash[:notice] = 'Error' 
     redirect_to '/settings/password' 
    end 

    end 

어떤 아이디어 :

여기
Started POST "/settings/password/update" for 127.0.0.1 at 2011-08-11 11:37:05 -0700 
    Processing by SettingsController#password_update as HTML 
    Parameters: {"utf8"=>"✓", "authenticity_token"=>"QBZP/h0Xg1SOBWh0+JwzFRyC8X7pE50mx1CgeS6+iNY=", "user"=>{"current_password"=>"[FILTERED]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Change my password"} 
    User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1 
    SQL (0.2ms) BEGIN 
WARNING: Can't mass-assign protected attributes: current_password 
    AREL (0.7ms) UPDATE "users" SET "encrypted_password" = '$2a$10$cjq9eWB41aqeukarMzyciO4adXB3g.gCSwP6OouV0HT9HZI3IVIa6', "updated_at" = '2011-08-11 18:37:06.326258' WHERE "users"."id" = 3 
[paperclip] Saving attachments. 
    SQL (25.7ms) COMMIT 
Redirected to http://localhost:3000/settings/account 
Completed 302 Found in 556ms 

는 password_update의 컨트롤러 방법은? 나는 current_password를 설정하려고하지 않고 있지만 암호를 업데이트하기 위해 패스해야한다고 생각하니? 감사합니다

+0

이상한 것은이 암호를 업데이트하지만 밖으로 후 사용자에 서명되어 사용자 모델에 대한 방법을 update_without_password 오버라이드 (override)하는 것을 선호? – AnApprentice

답변

2

귀하의 사용자 모델에 attr_accessible :current_password을 추가하십시오.

+3

이것을 시도하면'unknown attribute : current_password'가됩니다. –

+1

나도. ': current_password'는 User 객체의 속성이 아닙니다. – rodrigoalves

+6

그러면 모델에'attr_accessor : current_password'를 추가해야 할 수도 있습니다. 또한 이러한 링크는 도움이 될 수 있습니다 : [1] (https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-password) 및 [2] (https : // github.com/plataformatec/devise/issues/1620) – manafire

3

나는

def update_without_password(params={}) 
    params.delete(:current_password) 
    super(params) 
end 
관련 문제