def sortable_by(*attributes)
      config  = _sortable_by_config
      opts    = attributes.extract_options!
      default = opts.delete(:default)

      attributes.each do |name|
        config.field(name, opts)
      end
      config.default(default) if default
      yield config if block_given?
      config
    end
def sortable_by(*attributes)
      config  = _sortable_by_config
      opts    = attributes.extract_options!
      default = opts.delete(:default)

      attributes.each do |name|
        config.field(name, opts)
      end
      config.default(default) if default
      yield config if block_given?
      config
    end
Declare sortable attributes and scopes. Examples:

   # Simple
   class Post < ActiveRecord::Base
     sortable_by :title, :id
   end

   # Case-insensitive
   class Post < ActiveRecord::Base
     sortable_by do |x|
       x.field :title, as: arel_table[:title].lower
       x.field :id
     end
   end

   # With default
   class Post < ActiveRecord::Base
     sortable_by :id, :topic, :created_at,
       default: 'topic,-created_at'
   end

   # Composition
   class App < ActiveRecord::Base
     sortable_by :name, default: '-version' do |x|
       x.field :version, as: %i[major minor patch]]
     end
   end

   # Associations (eager load)
   class Product < ActiveRecord::Base
     belongs_to :shop

     sortable_by do |x|
       x.field :name
       x.field :shop, as: Shop.arel_table[:name].lower, eager_load: :shop
       x.default 'shop,name'
     end
   end

   # Associations (custom scope)
   class Product < ActiveRecord::Base
     belongs_to :shop

     sortable_by do |x|
       x.field :shop, as: Shop.arel_table[:name].lower, scope: -> { joins(:shop) }
     end
   end