2015-12-25 67 views
2

使用Rails 4,設計,簡單的形式。讀了很多關於這個,但肯定沒有足夠的經驗。我做了RegistrationController,自定義視圖也存在。 有了這個,我有密碼確認沒有問題,但我所有的PARAMS是不允許的:在沒有密碼確認的情況下設計更新附加屬性。

def update_resource(resource, params) 
    resource.update_without_password(params) 
end 

據我所知,這應該是決定,但對我沒有任何影響:

def configure_account_update_params 
    devise_parameter_sanitizer.for(:account_update) do |u| 
     u.permit(:username, :first_name, :last_name, :price_plan_id, :email_notify, :msg_notify, 
       :email, :password, :password_confirmation, :current_password) 
    end 
    end 

也許有人能寫出關於它的整個概念性答案嗎?

+0

你在註冊控制器中放了before_filter:configure_permitted_pa​​rameters嗎? –

+0

@DileepNandanam這個任務迭代太多了。你是對的,在這裏我忘了說。非常感謝,一切正常。在我的情況下,回調函數是'before_filter:configure_account_update_params,只有:[:update]'隨意寫答案,我會接受它。 – nobilik

回答

1

啓用那些誰錯過了回調。

class ApplicationController < ActionController::Base 
    before_action :configure_account_update_params, if: :devise_controller? 
0

在我的模型,設計被賦予我已經添加了這些方法:

def skip_devise 
    @skip = true 
end 

def password_required? 
    [email protected]? ? false : super 
end 

def email_required? 
    [email protected]? ? false : true 
end 

您的模型將覆蓋設計的password_required?email_required?方法。

當我想要我的模型跳過這些驗證我剛剛運行此:

my_model.skip_devise 
my_model.save! 
相關問題