Skip to content

Commit

Permalink
lazy-load the sort order to prevent hitting the DB in rake tasks
Browse files Browse the repository at this point in the history
resolves #2342
  • Loading branch information
seanlinsley committed Sep 20, 2013
1 parent 3355078 commit ba2d10f
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/active_admin/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ class Resource
attr_reader :collection_actions

# The default sort order to use in the controller
attr_accessor :sort_order
attr_writer :sort_order
def sort_order
@sort_order ||= (resource_class.respond_to?(:primary_key) ? resource_class.primary_key.to_s : 'id') + '_desc'
end

# Set the configuration for the CSV
attr_writer :csv_builder
Expand All @@ -57,8 +60,8 @@ module Base
def initialize(namespace, resource_class, options = {})
@namespace = namespace
@resource_class_name = "::#{resource_class.name}"
@options = default_options.merge(options)
@sort_order = @options[:sort_order]
@options = options
@sort_order = options[:sort_order]
@member_actions, @collection_actions = [], []
end
end
Expand Down Expand Up @@ -149,12 +152,6 @@ def resource

private

def default_options
{
:sort_order => (resource_class.respond_to?(:primary_key) ? resource_class.primary_key.to_s : 'id') + '_desc'
}
end

def default_csv_builder
@default_csv_builder ||= CSVBuilder.default_for_resource(resource_class)
end
Expand Down

0 comments on commit ba2d10f

Please sign in to comment.