How to get ActiveAdmin to work with Strong Parameters?

后端 未结 6 1615
鱼传尺愫
鱼传尺愫 2020-12-13 02:01

Update: this question was asked before there was a solution for it already in ActiveAdmin. As Joseph states, the ActiveAdmin documentation now contains this information,

6条回答
  •  青春惊慌失措
    2020-12-13 02:37

    The accepted answer did not work for me with resources defined in an engine, so I tracked down the original resource_params in inherited_resources/lib/inherited_resources/base_helpers.rb and came up with this solution which closer mimics that code, and which works with engines:

    In config/initializers/active_admin.rb:

    ActiveAdmin::ResourceController.class_eval do
      # Allow ActiveAdmin admins to freely mass-assign when using strong_parameters
      def resource_params
        [(params[resource_request_name] || params[resource_instance_name]).try(:permit!) || {}]
      end
    end
    

提交回复
热议问题