Administrate: How to add new attributes to permit?

Created on 29 Sep 2017  路  7Comments  路  Source: thoughtbot/administrate

Currently the ApplicationController methods has been changed a bit. resource_params method returns output of permitted params for other class - YourControllerDashboard instead of Admin::YourController. So, permitted_attributes method no longer belongs to the ApplicationController class, and neither used in it.
Let me know if I am wrong at this point, and if I am not - what will be a new solution?
I am digging around trying to use this workaround:

def dashboard
  super.permitted_attributes << :image
end

Reopening previous issue:

207

Most helpful comment

@lun4i I was able to get this working by defining permitted_attributes on the model dashboard

class ObjectDashboard < Administrate::BaseDashboard
  def permitted_attributes
    super + [:attribute_for_hidden_field]
  end
end

All 7 comments

@lun4i I was able to get this working by defining permitted_attributes on the model dashboard

class ObjectDashboard < Administrate::BaseDashboard
  def permitted_attributes
    super + [:attribute_for_hidden_field]
  end
end

Curious as if to why you need to add more permitted attributes outside of those listed in your dashboard class?

Would you be able to provide an example where this isn't working to help me understand it better?

I posted a more detailed example of what I did in a similar situation (controller action to add parameters now shown in the form).

Implementation detail - but if I had chosen to just mark the dashboard form field as read only - then I wouldn't have needed to muck about with overwriting the permitted_attributes.

I'm using v0.11.0, and tried

class MypageDashboard < Administrate::BaseDashboard
  def permitted_attributes
    super + [:my_search_condition_flag]
  end
end

but still getting found unpermitted parameter error.
I have posted detailed question on stackoverflow.
Please help me out.

What worked for me was overriding this method in the controlller:

    def resource_params
      params.require(resource_class.model_name.param_key).
        permit(dashboard.permitted_attributes << :my_params).
        transform_values { |v| read_param_value(v) }
    end

From the StackOverflow question, I can see this was referring to search parameters. That has been answered now (https://stackoverflow.com/questions/56607539/unpermitted-parameter-error-when-adding-request-parameter-while-using-administra), so I think this can be closed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MatthiasRMS picture MatthiasRMS  路  3Comments

migu0 picture migu0  路  3Comments

namiwang picture namiwang  路  4Comments

conwayanderson picture conwayanderson  路  4Comments

trandoanhung1991 picture trandoanhung1991  路  3Comments