app/controllers/administrate/application_controller.rb in administrate-0.18.0 vs app/controllers/administrate/application_controller.rb in administrate-0.19.0
- old
+ new
@@ -38,11 +38,11 @@
page: Administrate::Page::Form.new(dashboard, requested_resource),
}
end
def create
- resource = resource_class.new(resource_params)
+ resource = new_resource(resource_params)
authorize_resource(resource)
if resource.save
redirect_to(
after_resource_created_path(resource),
@@ -199,11 +199,11 @@
relation.includes(*resource_includes)
end
def resource_params
params.require(resource_class.model_name.param_key).
- permit(dashboard.permitted_attributes).
+ permit(dashboard.permitted_attributes(action_name)).
transform_values { |v| read_param_value(v) }
end
def read_param_value(data)
if data.is_a?(ActionController::Parameters) && data[:type]
@@ -212,10 +212,12 @@
else
raise "Unrecognised param data: #{data.inspect}"
end
elsif data.is_a?(ActionController::Parameters)
data.transform_values { |v| read_param_value(v) }
+ elsif data.is_a?(String) && data.blank?
+ nil
else
data
end
end
@@ -263,11 +265,11 @@
Administrate.warn_of_deprecated_authorization_method(__method__)
authorized_action?(resource, action)
end
helper_method :show_action?
- def new_resource
- resource_class.new
+ def new_resource(params = {})
+ resource_class.new(params)
end
helper_method :new_resource
def authorize_resource(resource)
if authorized_action?(resource, action_name)