2013-08-30 28 views
0

我正在使用覆蓋Devise RegistrationController的更新方法。Rails使用嵌套屬性設計無密碼更新保持回滾

update_with_password只是簡單地更新其他地方的用戶與其他窗體的密碼工作正常。而來到update_without_password,日誌可以看到它繼續回退(日誌可以見下文)

Started PUT "/users" for 127.0.0.1 at 2013-08-30 10:45:03 +1000 
Processing by RegistrationsController#update as HTML 
Parameters: {"utf8"=>"✓", "authenticity_token"=>"xxx", "user"=>{"name"=>"xxxxxx", "email"=>"[email protected]", "first_name"=>"xxx", "last_name"=>"xxx", "person_attributes"=>{"gender"=>"Unspecified", "description"=>"xxxxxx", "location"=>"xxx", "facebook"=>"https://www.facebook.com/xxxx", "website"=>"", "youtube"=>"", "wikipedia"=>"", "id"=>"11190"}}, "commit"=>"Save"} 
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = 11190 LIMIT 1 
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 11190]] 
(0.1ms) BEGIN 
**Person Load (0.5ms) SELECT "people".* FROM "people" WHERE "people"."user_id" = 11190 LIMIT 1** 
User Exists (0.5ms) SELECT 1 AS one FROM "users" WHERE ("users"."name" = 'xxxxxx' AND "users"."id" != 11190) LIMIT 1 
**(0.3ms) ROLLBACK** 
successfully_updated =======> false 
CACHE (0.0ms) SELECT "people".* FROM "people" WHERE "people"."user_id" = 11190 LIMIT 1 
Rendered devise/registrations/edit.html.erb within layouts/application (16.5ms) 

的更新方法如下:

def update 
    @user = User.find(current_user.id) 

    successfully_updated = if needs_password?(@user, params) 
    @user.update_with_password(params[:user]) 
    else 
    params[:user].delete(:current_password) 
    logger.info("USER params ====> #{params[:user]}") 

    @user.update_without_password(params[:user]) 
    end 
    logger.info("successfully_updated =======> #{successfully_updated}") ####### THIS ALWAYS SHOWS "false" 
    if successfully_updated 
    . 
    .(some extra code) 
    . 
    else 
    render "edit" 
    end 
end 

我已經檢查了模型,用戶具有accept_nested_attributes爲人Person模型具有此表單的所有attr_accessible。

任何想法,我有問題嗎?我一直試圖找出一些時間,但沒有運氣。謝謝你的時間。

回答

1

你應該檢查你的模型設定,如:accept_nested_attributes等,得到了前同樣的問題,但實在想不起我的所作所爲,以解決這個問題。

+0

現在你的模型中有什麼? – dax

+0

謝謝,我認爲問題是這**驗證:密碼,:presence => {:message =>'密碼是必需的'} **,所以表單不斷抱怨,因爲我需要用戶在通過期間註冊 – LPing

+0

解決了問題。我將上面的代碼更改爲** validates:password,:presence => {:message =>'password is required'},:on =>:create **,因此它只檢查create方法。感謝所有的幫助。 – LPing