Module: Custom::SelectHelper
- Included in:
- CurrencyHelper
- Defined in:
- app/helpers/custom/select_helper.rb
Instance Method Summary collapse
- #collection_for_select(collection, name, id, options = {}) ⇒ Object
- #collection_name_by_id(collection, id) ⇒ Object
Instance Method Details
#collection_for_select(collection, name, id, options = {}) ⇒ Object
10 11 12 13 14 15 16 |
# File 'app/helpers/custom/select_helper.rb', line 10 def collection_for_select(collection, name, id, = {}) return [] unless collection.is_a?(Array) collection = collection.map { |h| [ h[name], h[id] ] } collection = (collection, [:value]) if [:options_for_select].present? collection end |
#collection_name_by_id(collection, id) ⇒ Object
3 4 5 6 7 8 |
# File 'app/helpers/custom/select_helper.rb', line 3 def collection_name_by_id(collection, id) return false if collection.empty? element = collection.find { |hash| hash[:id] == id } element.try(:fetch, :name) end |