simple_form_ransack 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simple_form_ransack/form_proxy.rb +29 -7
- data/lib/simple_form_ransack/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 908f1e7b0caf9a74d9afd4ace8b8eb2bd59f4662
|
4
|
+
data.tar.gz: 733e44844b4490f02a83c9796763a55bc897abf7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97128aa38fa68a4dfed2bc346ea2f6496b5f48e5bc9f74a0977704469a6badb9711f87aeb51fbb6f800154e4988f754bf03a90db56ca69b29636a9408e3928a3
|
7
|
+
data.tar.gz: 0cf66c6a840b84598afab7d486da5c44e9269bc168929ff4e024a53af3afbe9d9b1e57673b1a418e9467205cde9fde63171e3b7fc86ae23f76446432fa3b6c79
|
@@ -16,16 +16,17 @@ class SimpleFormRansack::FormProxy
|
|
16
16
|
opts = {}
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
attribute_name = match[1]
|
22
|
-
else
|
23
|
-
raise "Couldn't figure out attribute name from: #{name}"
|
24
|
-
end
|
19
|
+
attribute_name = real_name(name, opts)
|
20
|
+
as = as_from_opts(opts)
|
25
21
|
|
26
22
|
input_html = opts.delete(:input_html) || {}
|
27
23
|
input_html[:name] = "q[#{name}]" unless input_html.key?(:name)
|
28
|
-
|
24
|
+
|
25
|
+
if as == "select"
|
26
|
+
opts[:selected] = @params[name] if !input_html.key?(:selected) && @params[name]
|
27
|
+
else
|
28
|
+
input_html[:value] = @params[name] if !input_html.key?(:value) && @params[name]
|
29
|
+
end
|
29
30
|
|
30
31
|
opts[:input_html] = input_html
|
31
32
|
opts[:required] = false unless opts.key?(:required)
|
@@ -37,4 +38,25 @@ class SimpleFormRansack::FormProxy
|
|
37
38
|
def method_missing(method_name, *args, &blk)
|
38
39
|
@form.__send__(method_name, *args, &blk)
|
39
40
|
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def as_from_opts(opts)
|
45
|
+
if opts[:as].present?
|
46
|
+
return opts[:as].to_s
|
47
|
+
elsif opts[:collection]
|
48
|
+
return "select"
|
49
|
+
end
|
50
|
+
|
51
|
+
return "text"
|
52
|
+
end
|
53
|
+
|
54
|
+
def real_name(name, opts)
|
55
|
+
match = name.to_s.match(/^(.+)_(eq|cont|eq_any)$/)
|
56
|
+
if match
|
57
|
+
return match[1]
|
58
|
+
else
|
59
|
+
raise "Couldn't figure out attribute name from: #{name}"
|
60
|
+
end
|
61
|
+
end
|
40
62
|
end
|