simple_form_ransack 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4dae9f1f5969a907d9edd65a9544387e00a0d8e6
4
- data.tar.gz: 7d47d189be6c2813cf2496eb64e7d5d5fbda0956
3
+ metadata.gz: b62806d6d76f54996dffb15b1f5b5e1841da3011
4
+ data.tar.gz: e4341086af8437446c47b71e6140fb10a8de7989
5
5
  SHA512:
6
- metadata.gz: bd1fa558b38d90876e3e6f1406d566ef061ddb0550ae08800d6b4dbd16bd3f8a5225ba2c3568f9c9960e7b08fc0c8d79ab103ec8aa1fde566f5b3bd962f9ab46
7
- data.tar.gz: 2557ce5258751b0c5bb12118684bcca244dad7c0334dfc802bc98ad883e687caab6c1064bea5338a0a67a200836826ee58e89b96d4c016f2da1fa4aa856ed61d
6
+ metadata.gz: 5afd9876c38b25d9bc38650f1b134ad5b14d608b7721f17b05eb837ca79f0664d4524d66ce74532af8734700471c3a2bbc9dc23a007eedf48d250e729f99e702
7
+ data.tar.gz: 2e73a09f2e74dd016e57fc8aae295870d09c035646078be099cd22490d0d6b54c6f0ad10deb28ec7dc0b25d3009abc7b4311b9f50ee970b3502b66ed498ea7ef
@@ -12,14 +12,13 @@ module SimpleFormRansackHelper
12
12
 
13
13
  model_class = ransack.klass
14
14
  sample_model = model_class.new
15
-
16
- search_key = ransack.context.search_key
15
+ ransack_params = ransack.instance_variable_get(:@_registered_params)
17
16
 
18
17
  simple_form_for(sample_model, *args) do |form|
19
18
  form_proxy = SimpleFormRansack::FormProxy.new(
20
19
  ransack: ransack,
21
20
  form: form,
22
- params: params[search_key] || {}
21
+ params: ransack_params
23
22
  )
24
23
 
25
24
  yield form_proxy
@@ -5,8 +5,9 @@ module SimpleFormRansack
5
5
 
6
6
  def self.locale_files
7
7
  files = []
8
+ available_locales = (I18n.available_locales + Rails.application.config.i18n.available_locales).uniq
8
9
 
9
- I18n.available_locales.each do |locale|
10
+ available_locales.each do |locale|
10
11
  path = "#{File.realpath("#{File.dirname(__FILE__)}/../config/locales")}/#{locale}.yml"
11
12
  files << File.realpath(path) if File.exist?(path)
12
13
  end
@@ -16,3 +17,4 @@ module SimpleFormRansack
16
17
  end
17
18
 
18
19
  require_relative "../app/helpers/simple_form_ransack_helper"
20
+ require_relative "simple_form_ransack/ransack_search_monkey_patch"
@@ -34,6 +34,7 @@ private
34
34
 
35
35
  set_value
36
36
  set_name
37
+ set_include_blank
37
38
  set_label if @attribute_name && !@opts.key?(:label)
38
39
 
39
40
  @args << @opts
@@ -56,7 +57,7 @@ private
56
57
  if @opts[:as].present?
57
58
  @as = @opts.fetch(:as).to_s
58
59
  elsif @opts[:collection]
59
- @as = "select"
60
+ calculate_as_collection
60
61
  elsif @attribute_name.to_s.end_with?("country")
61
62
  @as = "country"
62
63
  elsif column && column.type == :boolean
@@ -66,8 +67,18 @@ private
66
67
  @as ||= "string"
67
68
  end
68
69
 
70
+ def calculate_as_collection
71
+ if @match_type == "eq_any"
72
+ @as = "check_boxes"
73
+ else
74
+ @as = "select"
75
+ end
76
+ end
77
+
69
78
  def set_name
70
- @input_html[:id] = "q_#{@name}"
79
+ # This overrides the individual check boxes and messes up the label targets
80
+ # There won't be any main input anyway, so it doesn't mess anything up either
81
+ @input_html[:id] = "q_#{@name}" unless @as == "check_boxes"
71
82
 
72
83
  return if @input_html.key?(:name)
73
84
 
@@ -174,4 +185,10 @@ private
174
185
  @input_html[:value] = ""
175
186
  end
176
187
  end
188
+
189
+ def set_include_blank
190
+ return if @opts.key?(:include_blank)
191
+ return if @as != "select" && @as != "country"
192
+ @opts[:include_blank] = true
193
+ end
177
194
  end
@@ -0,0 +1,11 @@
1
+ require "ransack"
2
+
3
+ # This saves the params given to Ransack, so they can be recalled later
4
+ class Ransack::Search
5
+ alias old_build build
6
+
7
+ def build(params = {})
8
+ @_registered_params = params
9
+ old_build(params)
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module SimpleFormRansack
2
- VERSION = "0.0.13".freeze
2
+ VERSION = "0.0.14".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form_ransack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Johansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-23 00:00:00.000000000 Z
11
+ date: 2016-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -195,6 +195,7 @@ files:
195
195
  - lib/simple_form_ransack/attribute_inspector.rb
196
196
  - lib/simple_form_ransack/form_proxy.rb
197
197
  - lib/simple_form_ransack/input_manipulator.rb
198
+ - lib/simple_form_ransack/ransack_search_monkey_patch.rb
198
199
  - lib/simple_form_ransack/version.rb
199
200
  - lib/tasks/simple_form_ransack_tasks.rake
200
201
  homepage: https://www.github.com/kaspernj/simple_form_ransack