facet_for 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  facet_for is a collection of FormBuilder helpers that speed up the process of creating complex search forms with [Ransack](http://github.com/ernie/ransack).
4
4
 
5
- For many searches, it can be as simple as:
5
+ For many searches, it can be as simple as adding this inside your ```search_form_for```:
6
6
 
7
7
  ```ruby
8
8
  <%= f.facet_for(:field_name) -%>
@@ -39,17 +39,21 @@ Most of the Ransack predicates are supported:
39
39
 
40
40
  As well as several special cases and meta-predicates specific to facet_for:
41
41
 
42
- #### Collections
42
+ #### Between
43
+
44
+ By default, when passing a ```date``` or ```datetime``` column to facet_for, it will use the ```:type => :between``` predicate.
43
45
 
44
- * Collection - ```:type => :collection```
46
+ Rather than generating a single field, ```:type => :between``` creates one ```:type => :lte``` and one ```:type => :gte``` field with a single label. This makes searching ranges of dates or numbers painless.
47
+
48
+ #### Collections
45
49
 
46
- 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.
50
+ By default, when passing a ```has_many``` or ```belongs_to``` association into facet_for, it will choose the ```:type => :collection``` predicate. This produces a ```collection_select``` with the unique options for that association.
47
51
 
48
52
  When using ```:type => :collection``` on a column in the database, rather than an association, it defaults to all unique options.
49
53
 
50
54
  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.
51
55
 
52
- * Contains Any - ```:type => :cont_any```
56
+ #### Contains Any
53
57
 
54
58
  ```: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```.
55
59
 
data/lib/facet_for.rb CHANGED
@@ -14,7 +14,9 @@ module FacetFor
14
14
  ['Between', :between],
15
15
  ['Is Null', :null],
16
16
  ['Is Not Null', :not_null],
17
- ['Collection', :collection]
17
+ ['Collection', :collection],
18
+ ['Is True', :true],
19
+ ['Is False', :false]
18
20
  ]
19
21
 
20
22
  def self.predicates
@@ -101,6 +103,7 @@ module FacetFor
101
103
  # Ransack will then look at the _id column for the associated model.
102
104
  # This won't work properly on models with nonstandard id column
103
105
  # names. That's a problem, but whatevs for the time being.
106
+ @facet[:association_class] = association.first.klass
104
107
  @facet[:association_name] = "#{association.first.plural_name}"
105
108
  @facet[:column_name] = "#{association.first.plural_name}_id"
106
109
  @facet[:clean_column_name] = "#{association.first.name.to_s.singularize}_id"
@@ -109,7 +112,7 @@ module FacetFor
109
112
 
110
113
  # If we're dealing with belongs_to, we can assume we just want
111
114
  # to look at the foreign key on the current model. Much simpler.
112
-
115
+ @facet[:association_class] = association.first.klass
113
116
  @facet[:association_name] = association.first.name
114
117
  @facet[:column_name] = association.first.foreign_key
115
118
 
@@ -125,7 +128,7 @@ module FacetFor
125
128
  # based on this association. We only want to use distinct values.
126
129
  # This could probably be cleaner, but it works.
127
130
 
128
- @facet[:collection] = @facet[:model].unscoped.joins(@facet[:association_name].to_sym).select("DISTINCT #{clean_column}").where("#{clean_column} IS NOT NULL").map { |m| @facet[:association_name].to_s.singularize.camelcase.constantize.find(m.send(clean_column)) }
131
+ @facet[:collection] = @facet[:model].unscoped.joins(@facet[:association_name].to_sym).select("DISTINCT #{clean_column}").where("#{clean_column} IS NOT NULL").map { |m| @facet[:association_class].to_s.singularize.camelcase.constantize.find(m.send(clean_column)) }
129
132
 
130
133
  end
131
134
  else
@@ -1,3 +1,3 @@
1
1
  module FacetFor
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facet_for
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-09 00:00:00.000000000Z
12
+ date: 2012-01-12 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ransack
16
- requirement: &84788010 !ruby/object:Gem::Requirement
16
+ requirement: &76306010 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *84788010
24
+ version_requirements: *76306010
25
25
  description: Provides helpers for creating search forms with Ransack
26
26
  email:
27
27
  - jbarket@sleepunit.com
@@ -52,7 +52,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
52
52
  version: '0'
53
53
  segments:
54
54
  - 0
55
- hash: 432141005
55
+ hash: -827318161
56
56
  required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  version: '0'
62
62
  segments:
63
63
  - 0
64
- hash: 432141005
64
+ hash: -827318161
65
65
  requirements: []
66
66
  rubyforge_project: facet_for
67
67
  rubygems_version: 1.8.10