Module: BootstrapAutocompleteInput::Controllers::Autocomplete
- Included in:
- ActionController::Base
- Defined in:
- lib/bootstrap_autocomplete_input/controllers/autocomplete.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #autocomplete_option_limit(options) ⇒ Object
-
#get_object(model_sym) ⇒ Object
Returns parameter model_sym as a constant.
-
#items_to_json(items, method_display_id, method_display_value) ⇒ Object
Returns an array of [id, name].
Class Method Details
.included(target) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/bootstrap_autocomplete_input/controllers/autocomplete.rb', line 7 def self.included(target) target.extend BootstrapAutocompleteInput::Controllers::Autocomplete::ClassMethods if defined?(Mongoid::Document) target.send :include, BootstrapAutocompleteInput::Orm::Mongoid elsif defined?(MongoMapper::Document) target.send :include, BootstrapAutocompleteInput::Orm::MongoMapper else target.send :include, BootstrapAutocompleteInput::Orm::ActiveRecord end end |
Instance Method Details
#autocomplete_option_limit(options) ⇒ Object
49 50 51 |
# File 'lib/bootstrap_autocomplete_input/controllers/autocomplete.rb', line 49 def autocomplete_option_limit() [:limit] ||= 10 end |
#get_object(model_sym) ⇒ Object
Returns parameter model_sym as a constant
55 56 57 |
# File 'lib/bootstrap_autocomplete_input/controllers/autocomplete.rb', line 55 def get_object(model_sym) object = model_sym.to_s.camelize.constantize end |
#items_to_json(items, method_display_id, method_display_value) ⇒ Object
Returns an array of [id, name]
62 63 64 65 66 67 68 69 |
# File 'lib/bootstrap_autocomplete_input/controllers/autocomplete.rb', line 62 def items_to_json(items, method_display_id, method_display_value) items.collect do |item| v = item.send(method_display_value) id = item.send(method_display_id) [id.to_s, v.to_s] end end |