-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
-
What were you trying to do?
Upgraded from0.13tomain(9e462f7). I tried to define different attributes for new/create or edit/update actions as stated here: https://github.com/thoughtbot/administrate/blob/main/docs/customizing_dashboards.md#form-attributesWhen trying to
updateorcreatea record in the dashboard, there is a crash. This is because, when validating permitted attributes, it's trying to get these attributes fromself.class::FORM_ATTRIBUTESbut it should get them from"FORM_ATTRIBUTES_#{action.upcase}"asFORM_ATTRIBUTESis not defined anymore.specific_form_attributes_for(action)is returningnilbecauseactionis not being passed inpermitted_attributes. So the solution is to pass theaction_namewhen checking permitted attributes. -
What did you end up with (logs, or, even better, example apps are great!)?
The affected code is related with Allow different form attributes for new/update actions #1991
Logs:

My workaround:
In myUserDashboardadded the following overrides:def permitted_attributes(action) action = case action when "update" then "edit" when "create" then "new" else action end form_attributes(action).map do |attr| attribute_types[attr].permitted_attribute( attr, resource_class: self.class.model ) end.uniq end def form_attributes(action = nil) specific_form_attributes_for(action) || self.class::FORM_ATTRIBUTES end def specific_form_attributes_for(action) return unless action cname = "FORM_ATTRIBUTES_#{action.upcase}" self.class.const_get(cname) if self.class.const_defined?(cname) end
In my
Admin::UsersControlleradd the following override:def resource_params params.require(resource_class.model_name.param_key) .permit(dashboard.permitted_attributes(action_name)) .transform_values { |v| read_param_value(v) } end
-
What versions are you running?
- Rails: 6.1.3.1
- administrate (9e462f7)