Module: ApplicationHelper

Defined in:
lib/hopsoft/acts_as_lookup.rb

Instance Method Summary collapse

Instance Method Details

#select_from_lookup(table, options = {}) ⇒ Object



277
278
279
280
281
282
283
284
285
286
# File 'lib/hopsoft/acts_as_lookup.rb', line 277

def select_from_lookup(table, options = {})
  if table.is_a?(Symbol) || table.is_a?(String)
    model = Object.const_get(table.to_s.classify)
    field ||= options[:field] || "name"
    collection = model.send(:find, :all)
    default ||= options[:value] || nil
    choices = options_from_collection_for_select(collection, "name", field, default)
    select_tag table, choices, options
  end
end