Administrate: Is there a reason permitted params is limited to `FORM_ATTRIBUTES`

Created on 10 Nov 2015  路  7Comments  路  Source: thoughtbot/administrate

There has been a use case for me where I've wanted to include a hidden field but it's been rejected as it's not in the FORM_ATTRIBUTES. I've forked my own Administrate and have made changes specific to my use case but wondered if this was intentional or if others would find it useful. In which case I can pop it up here in a PR.

Most helpful comment

Hey, @tomgatzgates - you should be able to customize the permitted attributes list by overriding the method in your controller. For example:

class Admin::CustomersController
  def permitted_attributes
    super + [:attribute_for_hidden_field]
  end
end

Let me know if that works. We can add documentation around that.

All 7 comments

Hey, @tomgatzgates - you should be able to customize the permitted attributes list by overriding the method in your controller. For example:

class Admin::CustomersController
  def permitted_attributes
    super + [:attribute_for_hidden_field]
  end
end

Let me know if that works. We can add documentation around that.

I overwrote it in our fork of administrate, was generally just curious.

Hey, @tomgatzgates - sorry for the confusion. You shouldn't need to fork administrate to add permitted attributes to the list.

The recommended way to add permitted attributes to, for example, the Customer model, is to open up app/controllers/admin/customers_controller.rb and add the permitted_attributes method from my above comment there.

This can be done entirely in your app, without needing a fork of Administrate.

Does that answer your question? Let me know if I misunderstood.

@tomgatzgates I'm going to assume you got this figured out - let me know if there's something I need to do.

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

Cheers

Hi @lun4i! Could I get you to open a new issue with this as this one was closed a long time ago? We'll take it from there.

FWIW, I hit this problem and added posted solution from graysonwright to my dashboard (not controller) and it's working fine

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stephenson picture stephenson  路  3Comments

kwerle picture kwerle  路  4Comments

ACPK picture ACPK  路  4Comments

steffenix picture steffenix  路  4Comments

Reedian picture Reedian  路  4Comments