lib/acts_as_data_table/scope_filters/action_controller.rb
def scope_filters(options = {})
            #Include on-demand methods
            include Acts::DataTable::Shared::ActionController::OnDemand

            #Add helper methods to this controller's views
            helper :acts_as_data_table

            model_name = (options.delete(:model) || self.name.underscore.split('/').last.sub('_controller', '')).to_s.camelize.singularize

            #Create a custom before filter
            around_filter(options) do |controller, block|

              sf_params = controller.request.params[:scope_filters]

              begin

                #Set current filters before adding/removing based on the current request
                #This is needed for certain actions within the session
                Acts::DataTable::ScopeFilters::ActionController.set_request_filters!(model_name, controller.acts_as_data_table_session.active_filters)

                #Ensure that any scope filter related params are given and
                #that the given action is valid (add a filter, remove a filter, remove all filters)
                if sf_params.present? && %w(add remove reset).include?(sf_params[:action])
                  case sf_action = sf_params[:action].to_s
                  when 'add'
                    #Ensure that a group and a scope name are given
                    if [:group, :scope].all? { |p| sf_params[p].present? }
                      unless controller.acts_as_data_table_session.add_filter(sf_params[:group], sf_params[:scope], sf_params[:args])
                        #TODO: add error message if the validation failed or the filter was not available
                      end
                    end
                  when 'remove'
                    #Ensure that a group and a filter name are given
                    if sf_params[:group].present?
                      controller.acts_as_data_table_session.remove_filter!(sf_params[:group])
                    end
                  when 'reset'
                    controller.acts_as_data_table_session.remove_all_filters!
                  else
                    raise ArgumentError.new "Invalid scope filter action '#{sf_action}' was given."
                  end
                end

                #Set the updated filters
                Acts::DataTable::ScopeFilters::ActionController.set_request_filters!(model_name, controller.acts_as_data_table_session.active_filters)
                block.call
              ensure
                Acts::DataTable::ScopeFilters::ActionController.clear_request_filters!
              end
            end
          end
#
# Adds scope filter support to this controller (or parts of it)
#
# @param [Hash] options
#   Options to customize the behaviour
#
# @option options [Array<Symbol>] :only
#   If given, filters are only applied to actions which are in the given array
#
# @option options [Array<Symbol>] :except
#   If given, filters are only applied to actions which _not_ in the given array
#
# @option options [String, Symbol] :model
#   The model name which will be used as filter base.
#   If not given, the name is inferred from the controller name
#
Adds scope filter support to this controller (or parts of it)
Adds scope filter support to this controller ( or parts of it )
def scope_filters(options = {})
            include Acts::DataTable::Shared::ActionController::OnDemand
            helper :acts_as_data_table
            model_name = (options.delete(:model) || self.name.underscore.split('/').last.sub('_controller', '')).to_s.camelize.singularize
            around_filter(options) do |controller, block|
              sf_params = controller.request.params[:scope_filters]
              begin
                Acts::DataTable::ScopeFilters::ActionController.set_request_filters!(model_name, controller.acts_as_data_table_session.active_filters)
                if sf_params.present? && %w(add remove reset).include?(sf_params[:action])
                  case sf_action = sf_params[:action].to_s
                  when 'add'
                    if [:group, :scope].all? { |p| sf_params[p].present? }
                      unless controller.acts_as_data_table_session.add_filter(sf_params[:group], sf_params[:scope], sf_params[:args])
                      end
                    end
                  when 'remove'
                    if sf_params[:group].present?
                      controller.acts_as_data_table_session.remove_filter!(sf_params[:group])
                    end
                  when 'reset'
                    controller.acts_as_data_table_session.remove_all_filters!
                  else
                    raise ArgumentError.new "Invalid scope filter action '#{sf_action}' was given."
                  end
                end
                Acts::DataTable::ScopeFilters::ActionController.set_request_filters!(model_name, controller.acts_as_data_table_session.active_filters)
                block.call
              ensure
                Acts::DataTable::ScopeFilters::ActionController.clear_request_filters!
              end
            end
          end
def scope_filters ( options = { } ) include Acts :: DataTable :: Shared :: ActionController :: OnDemand helper :acts_as_data_table model_name = ( options . delete ( :model ) || self . name . underscore . split ( '/' ) . last . sub ( '_controller' , '' ) ) . to_s . camelize . singularize around_filter ( options ) do | controller , block | sf_params = controller . request . params [ :scope_filters ] begin Acts :: DataTable :: ScopeFilters :: ActionController . set_request_filters! ( model_name , controller . acts_as_data_table_session . active_filters ) if sf_params . present? && %w( add remove reset ) . include? ( sf_params [ :action ] ) case sf_action = sf_params [ :action ] . to_s when 'add' if [ :group , :scope ] . all? { | p | sf_params [ p ] . present? } unless controller . acts_as_data_table_session . add_filter ( sf_params [ :group ] , sf_params [ :scope ] , sf_params [ :args ] ) end end when 'remove' if sf_params [ :group ] . present? controller . acts_as_data_table_session . remove_filter! ( sf_params [ :group ] ) end when 'reset' controller . acts_as_data_table_session . remove_all_filters! else raise ArgumentError . new "Invalid scope filter action '#{sf_action}' was given." end end Acts :: DataTable :: ScopeFilters :: ActionController . set_request_filters! ( model_name , controller . acts_as_data_table_session . active_filters ) block . call ensure Acts :: DataTable :: ScopeFilters :: ActionController . clear_request_filters! end end end
Adds scope filter support to this controller (or parts of it)
Adds scope filter support to this controller ( or parts of it )
#Include on-demand methods #Add helper methods to this controller's views #Create a custom before filter #Set current filters before adding/removing based on the current request #This is needed for certain actions within the session #Ensure that any scope filter related params are given and #that the given action is valid (add a filter, remove a filter, remove all filters) #Ensure that a group and a scope name are given #TODO: add error message if the validation failed or the filter was not available #Ensure that a group and a filter name are given #Set the updated filters
options
:model The model name which will be used as filter base. If not given, the name is inferred from the controller name
: model The model name which will be used as filter base . If not given the name is inferred from the controller name
options Options to customize the behaviour
options Options to customize the behaviour