Module: Handles::SortableColumns::MetaClassMethods

Defined in:
lib/handles/sortable_columns.rb

Overview

Config

Instance Method Summary collapse

Instance Method Details

#handles_sortable_columns(fopts = {}, &block) ⇒ Object

Activate and optionally configure the sortable columns feature in your controller.

class MyController < ApplicationController
  handles_sortable_columns
  ...

With configuration:

class MyController < ApplicationController
  handles_sortable_columns do |conf|
    conf.sort_param = "s"
    conf.page_param = "p"
    conf.indicator_text = {}
    ...
  end
  ...

With filter options:

class MyController < ApplicationController
  handles_sortable_columns(:only => [:index]) do |conf|
    ...
  end
  ...

NOTE: conf is a Config object.



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/handles/sortable_columns.rb', line 124

def handles_sortable_columns(fopts = {}, &block)
  # Multiple activation protection.
  if not self < InstanceMethods
    include InstanceMethods
    helper_method :sortable_column
  end

  # Process configuration at every activation.
  before_filter(fopts) do |ac|
    ac.instance_eval do
      # NOTE: Can't `yield`, we're in a block already.
      block.call(sortable_columns_config) if block
    end
  end
end