effective_form_inputs 0.7.4 → 0.7.5
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfe1f299c36eb92e01218a5cfa7fd64cbef52398
|
4
|
+
data.tar.gz: 0ace3f60cc9f9790719fb07c3be576f4d0f82cf7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a94bfe9d38b9bf0ba806c2bd6088fbac47df703bbbc0c3702da11485c81fdef311fa32dea86cf5b86b0bb454533218d4dd95769ce3e357e5e320c54fd2b6b36e
|
7
|
+
data.tar.gz: 27b5de98a8a592ad3efafa7c6f68704b5926e5c0b523baf197dfd5c8585ed83fa9fc3ae0cc8ac4fc09510eae2ac3738aa5a7cb27091545764ab7e94945dec483
|
@@ -32,6 +32,7 @@ module Effective
|
|
32
32
|
|
33
33
|
# Set the value to avoid options craziness
|
34
34
|
@value = (@opts.delete(:value) || @html_opts.delete(:value) || (@object.send(@method) if @object.respond_to?(@method)))
|
35
|
+
@value = @value.to_a if @value.kind_of?(ActiveRecord::Relation)
|
35
36
|
end
|
36
37
|
|
37
38
|
def field_name
|
@@ -86,8 +86,8 @@ module Inputs
|
|
86
86
|
@method.to_s.sub('_id', '') + '_id'
|
87
87
|
end
|
88
88
|
|
89
|
-
def polymorphic_value
|
90
|
-
"#{
|
89
|
+
def polymorphic_value(obj)
|
90
|
+
"#{obj.model_name}_#{obj.to_param}" if obj.present?
|
91
91
|
end
|
92
92
|
|
93
93
|
def polymorphic_type_value
|
@@ -99,12 +99,30 @@ module Inputs
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def options
|
102
|
-
super().tap do |options|
|
103
|
-
options[:selected] = value if value
|
104
|
-
|
102
|
+
@effective_select_options ||= super().tap do |options|
|
105
103
|
options[:multiple] = true if (options[:tags] == true)
|
106
104
|
options[:include_blank] = (options[:multiple] != true)
|
107
|
-
|
105
|
+
|
106
|
+
# Fix the selected value, depending on our use case
|
107
|
+
if value.present?
|
108
|
+
case value
|
109
|
+
when Array
|
110
|
+
if options[:polymorphic]
|
111
|
+
options[:selected] = value.map { |value| (polymorhpic_value(value) rescue value) }
|
112
|
+
elsif value.first.respond_to?(options[:value_method]) # This is probably a belongs_to ActiveRecord object
|
113
|
+
options[:selected] = value.map { |value| (value.public_send(options[:value_method]) rescue value) }
|
114
|
+
end
|
115
|
+
else # Value is not an Array
|
116
|
+
if options[:polymorphic]
|
117
|
+
options[:selected] = polymorphic_value(value)
|
118
|
+
elsif value.respond_to?(options[:value_method]) # This is probably a belongs_to ActiveRecord object
|
119
|
+
options[:selected] = value.public_send(options[:value_method])
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
options[:selected] ||= value
|
124
|
+
end
|
125
|
+
|
108
126
|
end
|
109
127
|
end
|
110
128
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_form_inputs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|