Sha256: bfbeac21277550b4216806298a979a428bf68355075fa336d3176fd56f1eb53e

Contents?: true

Size: 1.19 KB

Versions: 13

Compression:

Stored size: 1.19 KB

Contents

# How to setup a predefined filter?
# ---------------------------------
#
# On your controllers:
#
#     def index
#       # Added predefined filter takes any argument, but in the views we
#       # expected the following:
#       #
#       #     add_predefined_filter(filter_name, action, scope)
#       #
#       ...
#       add_predefined_filter("Trash", "trash", "deleted")
#       ...
#     end
#
# On your views:
#
#     <% predefined_filters.each do |filter_name, action, scope| %>
#       ...
#     <% end %>
#

require 'active_support/concern'

module Admin
  module Filters

    extend ActiveSupport::Concern

    included do
      helper_method :predefined_filters
    end

    protected

    def add_predefined_filter(*args)
      predefined_filters
      @predefined_filters << args unless args.empty?
    end

    def prepend_predefined_filter(*args)
      predefined_filters
      @predefined_filters = @predefined_filters.unshift(args) unless args.empty?
    end

    def append_predefined_filter(*args)
      predefined_filters
      @predefined_filters = @predefined_filters.concat([args]) unless args.empty?
    end

    def predefined_filters
      @predefined_filters ||= []
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
brainsome_typus-4.0.0.beta13 app/controllers/concerns/admin/filters.rb
brainsome_typus-4.0.0.beta12 app/controllers/concerns/admin/filters.rb
brainsome_typus-4.0.0.beta11 app/controllers/concerns/admin/filters.rb
brainsome_typus-4.0.0.beta10 app/controllers/concerns/admin/filters.rb
brainsome_typus-4.0.0.beta9 app/controllers/concerns/admin/filters.rb
brainsome_typus-4.0.0.beta8 app/controllers/concerns/admin/filters.rb
brainsome_typus-4.0.0.beta7 app/controllers/concerns/admin/filters.rb
brainsome_typus-4.0.0.beta6 app/controllers/concerns/admin/filters.rb
brainsome_typus-4.0.0.beta5 app/controllers/concerns/admin/filters.rb
brainsome_typus-4.0.0.beta4 app/controllers/concerns/admin/filters.rb
brainsome_typus-4.0.0.beta3 app/controllers/concerns/admin/filters.rb
brainsome_typus-4.0.0.beta2 app/controllers/concerns/admin/filters.rb
brainsome_typus-4.0.0.beta1 app/controllers/concerns/admin/filters.rb