app/controllers/administrate/application_controller.rb in administrate-0.13.0 vs app/controllers/administrate/application_controller.rb in administrate-0.14.0

- old
+ new

@@ -25,11 +25,11 @@ page: Administrate::Page::Show.new(dashboard, requested_resource), } end def new - resource = resource_class.new + resource = new_resource authorize_resource(resource) render locals: { page: Administrate::Page::Form.new(dashboard, resource), } end @@ -99,16 +99,35 @@ def records_per_page params[:per_page] || 20 end def order - @order ||= Administrate::Order.new( - params.fetch(resource_name, {}).fetch(:order, nil), - params.fetch(resource_name, {}).fetch(:direction, nil), + @order ||= Administrate::Order.new(sorting_attribute, sorting_direction) + end + + def sorting_attribute + params.fetch(resource_name, {}).fetch( + :order, + default_sorting_attribute, ) end + def default_sorting_attribute + nil + end + + def sorting_direction + params.fetch(resource_name, {}).fetch( + :direction, + default_sorting_direction, + ) + end + + def default_sorting_direction + nil + end + def dashboard @dashboard ||= dashboard_class.new end def requested_resource @@ -142,9 +161,11 @@ if data[:type] == Administrate::Field::Polymorphic.to_s GlobalID::Locator.locate(data[:value]) else raise "Unrecognised param data: #{data.inspect}" end + elsif data.is_a?(ActionController::Parameters) + data.transform_values { |v| read_param_value(v) } else data end end