2015-03-12 22:43:13 +00:00
|
|
|
module StrongParams
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def permit_params(param_name, *accessible)
|
2015-04-27 22:16:35 +01:00
|
|
|
[param_name].flatten.inject(params.dup) do |pp, name|
|
|
|
|
pp = pp[name] || ActionController::Parameters.new
|
|
|
|
end.permit(*accessible.flatten)
|
2015-03-12 22:43:13 +00:00
|
|
|
end
|
2015-04-28 23:28:36 +01:00
|
|
|
|
|
|
|
|
2015-04-29 00:26:03 +01:00
|
|
|
def subject_params(subject_class, subject = nil)
|
|
|
|
permit_params(subject_class.name.underscore.to_sym, *policy(subject || subject_class).permitted_attributes)
|
2015-04-28 23:28:36 +01:00
|
|
|
end
|
2015-03-12 22:43:13 +00:00
|
|
|
end
|