Easily filter content by a list of characters
app/controllers/users_controller.rb
class UserController < ActionController::Base
def index
@users=User.letter_filter(:name, params[:letter])
end
end
app/views/users/index.html.haml
= glyph_filter
= render :partial => @users
- No active record model class methods. Just call the scope.
- Works with haml and erb
- Easily create a different layout by simply overriding the view partials
# Bundler Gemfile
gem 'glyph_filter'
# config/initializers/glyph_filter.rb
GlyphFilter.configure do |config|
# (optional) customize letters to filter by
# default is ("A".."Z").to_a
config.letters = ("b".."y").to_a
# (optional) customize param_name to use a different query param
# default is :letter
config.param_name = :glyph
# (optional) customize the string used to distinguish the 'left_over' content
# default is "?"
config.left_over = "!"
end
# Change the all filter name using i18n
en:
views:
filter_section:
all: ALL
- Fork the project
- Fix the issue
- Add unit tests
- Submit pull request on github
Copyright (c) 2011 Socialcast, Inc. See LICENSE.txt for further details.