工夫

2017-12-20 17 views
0

内のグローバル変数を変更するためにどのように私はこれを変更したい(devise.rbで定義されている):工夫

@@reset_password_keys = [:email] 

に:これは最終的に(required_attributesとして)使用されている

@@reset_password_keys = [:email, :role] 

authenticatable.rbで定義されている以下の方法でユーザーを検索します。

リセットパスワードフォームからemailroleの両方の属性を強制的に送信する場合に使用します。

使用法:あなたconfig/initializers/devise.rbファイルでそれを変更する必要があり

def find_or_initialize_with_errors(required_attributes, attributes, error=:invalid) #:nodoc: 
    attributes = if attributes.respond_to? :permit! 
    attributes.slice(*required_attributes).permit!.to_h.with_indifferent_access 
    else 
    attributes.with_indifferent_access.slice(*required_attributes) 
    end 
    attributes.delete_if { |key, value| value.blank? } 

    if attributes.size == required_attributes.size 
    record = find_first_by_auth_conditions(attributes) 
    end 

    unless record 
    record = new 

    required_attributes.each do |key| 
     value = attributes[key] 
     record.send("#{key}=", value) 
     record.errors.add(key, value.present? ? error : :blank) 
    end 
    end 

    record 
end 

答えて