Created
November 8, 2011 15:53
-
-
Save jeffkreeftmeijer/1348149 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/simple_form/inputs/base.rb b/lib/simple_form/inputs/base.rb | |
index 40c3e3f..4e12cf1 100644 | |
--- a/lib/simple_form/inputs/base.rb | |
+++ b/lib/simple_form/inputs/base.rb | |
@@ -130,13 +130,16 @@ module SimpleForm | |
joined_model_names = model_names.join(".") | |
model_names.shift | |
- lookups << :"#{joined_model_names}.#{lookup_action}.#{reflection_or_attribute_name}" | |
+ lookups << :"#{joined_model_names}.#{lookup_action}.#{reflection_or_attribute_name}" unless namespace == :options | |
lookups << :"#{joined_model_names}.#{reflection_or_attribute_name}" | |
end | |
lookups << :"#{reflection_or_attribute_name}" | |
lookups << default | |
- I18n.t(lookups.shift, :scope => :"simple_form.#{namespace}", :default => lookups).presence | |
+ lookup = lookups.shift | |
+ lookup = "#{lookup}.#{default}" if namespace == :options | |
+ | |
+ I18n.t(lookup, :scope => :"simple_form.#{namespace}", :default => lookups).presence | |
end | |
# Extract the model names from the object_name mess, ignoring numeric and | |
diff --git a/lib/simple_form/inputs/collection_input.rb b/lib/simple_form/inputs/collection_input.rb | |
index cc6fe1e..258d290 100644 | |
--- a/lib/simple_form/inputs/collection_input.rb | |
+++ b/lib/simple_form/inputs/collection_input.rb | |
@@ -29,7 +29,18 @@ module SimpleForm | |
def collection | |
@collection ||= begin | |
collection = options.delete(:collection) || self.class.boolean_collection | |
- collection.respond_to?(:call) ? collection.call : collection.to_a | |
+ collection = collection.respond_to?(:call) ? collection.call : collection.to_a | |
+ | |
+ if collection.is_a?(Array) | |
+ if collection.map(&:class).include?(Array) | |
+ collection.map { |label, value| [label.is_a?(Symbol) ? translate(:options, label) : label, value] } | |
+ else | |
+ collection.map { |label| [label.is_a?(Symbol) ? translate(:options, label) : label, label] } | |
+ end | |
+ else | |
+ collection | |
+ end | |
+ | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Possible suggestion: