Class: EffectiveSelectInput
- Inherits:
-
SimpleForm::Inputs::CollectionSelectInput
- Object
- SimpleForm::Inputs::CollectionSelectInput
- EffectiveSelectInput
- Defined in:
- lib/effective_form_inputs/inputs/effective_select_input.rb
Instance Method Summary collapse
-
#collection ⇒ Object
Apply ActsAsArchived behavior.
- #input(wrapper_options = nil) ⇒ Object
- #translate(collection) ⇒ Object
Instance Method Details
#collection ⇒ Object
Apply ActsAsArchived behavior.
18 19 20 21 22 23 |
# File 'lib/effective_form_inputs/inputs/effective_select_input.rb', line 18 def collection @collection ||= begin collection = translate(.delete(:collection)) || self.class.boolean_collection collection.respond_to?(:call) ? collection.call : collection.to_a end end |
#input(wrapper_options = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/effective_form_inputs/inputs/effective_select_input.rb', line 7 def input( = nil) label_method, value_method = (detect_collection_methods rescue [:to_s, :to_s]) [:collection] = collection [:label_method] = label_method unless [:polymorphic] [:value_method] = value_method unless [:polymorphic] Effective::FormBuilderInputs::EffectiveSelect.new(object, object_name, template, attribute_name, , ((, ) || {})).to_html end |
#translate(collection) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/effective_form_inputs/inputs/effective_select_input.rb', line 25 def translate(collection) return collection unless object.respond_to?(:new_record?) return collection unless collection.respond_to?(:klass) && collection.klass.respond_to?(:acts_as_archived?) if object.new_record? collection.unarchived else collection.unarchived.or(collection.archived.where(collection.klass.primary_key => object.send(attribute_name))) end end |