effective_form_inputs 0.7.4 → 0.7.5

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: c4569c203c0939b4299583c21b84cdbb8899f0a1
4
- data.tar.gz: 6b96dd9835ce3866ed6d5fd174ab7eee5e463e7b
3
+ metadata.gz: dfe1f299c36eb92e01218a5cfa7fd64cbef52398
4
+ data.tar.gz: 0ace3f60cc9f9790719fb07c3be576f4d0f82cf7
5
5
  SHA512:
6
- metadata.gz: 7684f263fbbaa59b318d5c6c790045d487480d2074d3d0ad58a5685b4a5f7440c61fc15b83f666ba56afa9ce7b100f097c12b642671e07324b7784eafc40bdd7
7
- data.tar.gz: 1acda55bd40537351041c4400cba4a1ebfef0013205549806a8cd6302d230fa83aea0d0a71ffa80e787df03ff7cbec422eedabaa4b0b05270f83265d05d88574
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
- "#{value.model_name}_#{value.to_param}" if value.present?
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
- options[:selected] = polymorphic_value if options[:polymorphic]
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
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveFormInputs
2
- VERSION = '0.7.4'.freeze
2
+ VERSION = '0.7.5'.freeze
3
3
  end
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
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-15 00:00:00.000000000 Z
11
+ date: 2015-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails