6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/muffin/rails/controller_additions.rb', line 6
def prepare(operation, params: nil, request: nil, scope: nil)
if params.blank? && respond_to?(:params) && operation.respond_to?(:model_name)
if self.params.key?(operation.model_name.underscore)
params = self.params[operation.model_name.underscore].deep_dup.permit!.to_h
params.deep_transform_keys! do |key|
if key.to_s[/.+_attributes\Z/]
new_key = key.to_s.sub(/_attributes\Z/, "")
key.is_a?(Symbol) ? new_key.to_sym : new_key
else
key
end
end
end
end
request ||= try(:request)
scope ||= try(Muffin::Rails::SCOPE_ACCESSOR) || try(:current_user)
operation.new(params: params, request: request, scope: scope)
end
|