Module: Effective::CrudController::PermittedParams

Included in:
Effective::CrudController
Defined in:
app/controllers/concerns/effective/crud_controller/permitted_params.rb

Constant Summary collapse

BLACKLIST =
[:created_at, :updated_at, :logged_change_ids]

Instance Method Summary collapse

Instance Method Details

#resource_active_model_permitted_paramsObject

If the resource is ActiveModel, just permit all This can still be overridden by a controller



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/concerns/effective/crud_controller/permitted_params.rb', line 40

def resource_active_model_permitted_params
  permitted_name = params.key?(effective_resource.name) ? effective_resource.name : effective_resource.resource_name

  if Rails.env.development?
    Rails.logger.info "Effective::CrudController#resource_permitted_params:"
    Rails.logger.info "params.require(:#{permitted_name}).permit!"
  end

  if params[permitted_name].present?
    params.require(permitted_name).permit!
  else
    params.require((effective_resource.namespaces + [effective_resource.resource_name]).join('_')).permit!
  end
end

#resource_admin_permitted_paramsObject

Permit all params for the admin namespace



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/concerns/effective/crud_controller/permitted_params.rb', line 24

def resource_admin_permitted_params
  raise 'expected resource class to have effective_resource do .. end' if effective_resource.model.blank?
  raise 'expected to be called only on admin namespace' unless effective_resource.namespaces == ['admin']

  permitted_name = params.key?(effective_resource.name) ? effective_resource.name : effective_resource.resource_name

  if Rails.env.development?
    Rails.logger.info "Effective::CrudController#resource_admin_permitted_params:"
    Rails.logger.info "params.require(:#{permitted_name}).permit!"
  end

  params.require(permitted_name).permit!
end

#resource_permitted_paramsObject

This is only available to models that use the effective_resource do … end attributes block It will be called last, and only for those resources params.require(effective_resource.resource_name).permit!



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/concerns/effective/crud_controller/permitted_params.rb', line 9

def resource_permitted_params
  raise 'expected resource class to have effective_resource do .. end' if effective_resource.model.blank?

  permitted_params = permitted_params_for(resource, effective_resource.namespaces)
  permitted_name = params.key?(effective_resource.name) ? effective_resource.name : effective_resource.resource_name

  if Rails.env.development?
    Rails.logger.info "Effective::CrudController#resource_permitted_params:"
    Rails.logger.info "params.require(:#{permitted_name}).permit(#{permitted_params.to_s[1...-1]})"
  end

  params.require(permitted_name).permit(*permitted_params)
end