Rails strong parameters incremental addition -
does know, if strong_parameters gem, can incrementally add attributes below:
def user_params params[:user].permit(:name, :email) if current_user.admin? params[:user].permit(:is_admin) end end
here incrementally asking code permit :is_admin
parameter if current user admin. shouldn't add permitted list of parameters (:name
, :email
)?
they way have done put params in class strong-parameters railscast..
this way have this
class permittedparams < struct.new(:params,:admin) def administrator_attributes allowed = [:email, :name, :password, :password_confirmation, :password_digest] if admin.has_any_role? :realm_admin, :system_admin allowed << :active << :roles end allowed end .... other models .... def method_missing(method,*args,&block) attributes_name = method.to_s + '_attributes' if respond_to? attributes_name, false params.require(method).send(:permit, *method(attributes_name).call) else super end end end
then in controller call @administrator.update_attributes(permitted_params.administrator)
as array can build array, , use * pass permit.
Comments
Post a Comment