filter_form 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/lib/filter_form/input_options/number/money.rb +4 -0
- data/lib/filter_form/money_converter.rb +28 -0
- data/lib/filter_form/version.rb +1 -1
- data/lib/filter_form.rb +1 -1
- metadata +3 -3
- data/lib/filter_form/ransack/search.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6189d3b110196894801cee283b727c4dc3018086
|
4
|
+
data.tar.gz: af46f72476125da17a24b32f887d6cba28ff58d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17c3223cc02252a317a0a6ad186ef4c28a938141abbad1ffa94292fd790df2d4b0aa2395dfb73d9ae4abad771ae3d4953ace647269d6750eb2435ffde8b07838
|
7
|
+
data.tar.gz: 56fbb4db9539de5d13bc1882a32295e8f1363f95e88fea3c87745d230b130d085fe653bf95ecaac8a2824fc43cbc3aa34834c0267cc40863bf9918c689d4ecf1
|
data/README.md
CHANGED
@@ -82,6 +82,17 @@ You can show predicate selector:
|
|
82
82
|
<% end %>
|
83
83
|
```
|
84
84
|
|
85
|
+
#### Money
|
86
|
+
|
87
|
+
To filter by monetized attribute please add your controller:
|
88
|
+
|
89
|
+
```erb
|
90
|
+
class ApplicationController < ActionController::Base
|
91
|
+
include FilterForm::MoneyConverter
|
92
|
+
...
|
93
|
+
end
|
94
|
+
```
|
95
|
+
|
85
96
|
#### Select2
|
86
97
|
|
87
98
|
You can wrap your select in `select2`:
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module FilterForm
|
2
|
+
module MoneyConverter
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
before_filter :convert_money_param_name_and_value, only: :index
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def convert_money_param_name_and_value
|
12
|
+
money_column_name = resource_class.column_names.select { |c| c.end_with?('_cents') }.first
|
13
|
+
|
14
|
+
if money_column_name && params[:q]
|
15
|
+
money_attribute_name = money_column_name.dup.gsub('_cents', '')
|
16
|
+
money_param_name = params[:q].keys.select { |c| c.start_with?(money_attribute_name) }.first
|
17
|
+
|
18
|
+
if money_param_name
|
19
|
+
params[:q][money_param_name.gsub(money_attribute_name, "#{ money_attribute_name }_cents")] = params[:q].delete(money_param_name).to_f * 100
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def resource_class
|
25
|
+
self.class.name.split('::').last.gsub('Controller', '').singularize.constantize
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/filter_form/version.rb
CHANGED
data/lib/filter_form.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filter_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeny Li
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simple_form
|
@@ -120,7 +120,7 @@ files:
|
|
120
120
|
- lib/filter_form/input_options/string/base.rb
|
121
121
|
- lib/filter_form/input_options/string/date.rb
|
122
122
|
- lib/filter_form/input_options_builder.rb
|
123
|
-
- lib/filter_form/
|
123
|
+
- lib/filter_form/money_converter.rb
|
124
124
|
- lib/filter_form/simple_form/form_builder.rb
|
125
125
|
- lib/filter_form/version.rb
|
126
126
|
homepage: https://github.com/exAspArk/filter_form
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Ransack
|
2
|
-
class Search
|
3
|
-
def initialize(object, params = {}, options = {})
|
4
|
-
(params ||= {}).delete_if { |k, v| v.blank? && v != false }
|
5
|
-
convert_money_param_name_and_value!(object, params)
|
6
|
-
@context = Context.for(object, options)
|
7
|
-
@context.auth_object = options[:auth_object]
|
8
|
-
@base = Nodes::Grouping.new(@context, 'and')
|
9
|
-
build(params.with_indifferent_access)
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def convert_money_param_name_and_value!(object, params)
|
15
|
-
money_attribute_name = object.column_names.select { |c| c.end_with?('_cents') }.first
|
16
|
-
|
17
|
-
if money_attribute_name
|
18
|
-
money_attribute_name = money_attribute_name.dup.gsub('_cents', '')
|
19
|
-
money_param_name = params.keys.select { |c| c.start_with?(money_attribute_name) }.first
|
20
|
-
|
21
|
-
if money_param_name
|
22
|
-
params[money_param_name.gsub(money_attribute_name, "#{ money_attribute_name }_cents")] = params.delete(money_param_name).to_f * 100
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|