Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Provides helper methods for creating facets and filters with Ransack
Ruby
tag: v0.1.0

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
.gitignore
Gemfile
README.md
Rakefile
facet_for.gemspec

README.md

facet_for

facet_for is a collection of FormBuilder helpers that speed up the process of creating complex search forms with Ransack.

For many searches, it can be as simple as:

<%= f.facet_for(:field_name) -%>

facet_for will use the database column type to choose an appropriate Ransack predicate, then create both the label and field. It will also work for has_many and belongs_to associations.

Installation

Add gem 'facet_for' in your Gemfile

Options

Many options in facet_for can be overridden by passing hash options.

Predicates

To choose an alternate predicate, pass :type => :predicate.

Most of the Ransack predicates are supported:

  • Contains - :type => :cont
  • Doesn't Contain - :type => :not_cont
  • Starts With - :type => :start
  • Doesn't Start With - :type => :not_start
  • Ends With - :type => :end
  • Doesn't End With - :type => :not_end
  • Is Null - :type => :null
  • Is Not Null - :type => :not_null
  • True - :type => :true
  • False - :type => :false
  • Greater Than or Equal - :type => :gte
  • Less Than or Equal - :type => :lte

As well as several special cases and meta-predicates specific to facet_for:

Collections

  • Collection - :type => :collection

By default, when passing a has_many or belongs_to association into facet_for, it will choose the :collection predicate. This produces a collection_select with the unique options for that association.

When using :type => :collection on a column in the database, rather than an association, it defaults to all unique options.

To pass specific options, use :collection => [] to pass an array of options. This may either be a flat array of strings (eg ['Blue', 'Red', 'Green']), a flat array of objects (SomeModel.all```), or a nested array of name and value pairs.

  • Contains Any - :type => :cont_any

:type => :cont_any behaves in a nearly identical manner to :type => :collection, except that the collection is rendered as a series of check boxes rather than a collection_select.

Custom Labels

By default, facet_for will determine label text based on a combination of the field name and the predicate. This can be overwritten by specifying :label => 'Your Label Here'.

Something went wrong with that request. Please try again.