Module: StrongParamsHelper

Extended by:
ActiveSupport::Concern
Defined in:
lib/generators/propel_facets/templates/controllers/concerns/strong_params_helper.rb

Overview

Helper for defining strong parameters in this application

By including this into your controller, you will be allowed to define allowed parameters by calling ‘permitted_params` and passing a list of field names. This works specially for our application controllers structure where fields are found within `data` JSON property at the very root of a submitted payload

Instance Method Summary collapse

Instance Method Details

#resource_paramsObject

To be used by controller to parse params as strong params



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/generators/propel_facets/templates/controllers/concerns/strong_params_helper.rb', line 46

def resource_params
  permitted = self.class.all_permitted_params

  api_params = ApiParams.new(params, request)
  permitted_params = api_params.permit(permitted)

  if self.class.all_permitted_unknown_params.present?
    self.class.all_permitted_unknown_params.each do |key|
      next unless (params.include?(:data) && !params[:data][key].nil?) || !params[key].nil?
      permitted_params = permitted_params.merge({ key => api_params.force_permit(key) })
    end
  end

  permitted_params
end