Module: RecordSelect::ClassMethods
- Defined in:
- lib/record_select.rb
Instance Attribute Summary collapse
-
#record_select_config ⇒ Object
readonly
Returns the value of attribute record_select_config.
Instance Method Summary collapse
-
#record_select(options = {}) ⇒ Object
Enables and configures RecordSelect on your controller.
- #uses_record_select? ⇒ Boolean
Instance Attribute Details
#record_select_config ⇒ Object (readonly)
Returns the value of attribute record_select_config.
27 28 29 |
# File 'lib/record_select.rb', line 27 def record_select_config @record_select_config end |
Instance Method Details
#record_select(options = {}) ⇒ Object
Enables and configures RecordSelect on your controller.
Options
model
-
defaults based on the name of the controller
per_page
-
records to show per page when browsing
notify
-
a method name to invoke when a record has been selected.
order_by
-
a SQL string to order the search results
search_on
-
an array of searchable fields
full_text_search
-
a boolean for whether to use a %?% search pattern or not. default is false.
label
-
a proc that accepts a record as argument and returns an option label. default is to call record.to_label instead.
include
-
as for ActiveRecord::Base#find. can help with search conditions or just help optimize rendering the results.
You may also pass a block, which will be used as options.
20 21 22 23 24 25 |
# File 'lib/record_select.rb', line 20 def record_select( = {}) [:model] ||= self.to_s.split('::').last.sub(/Controller$/, '').pluralize.singularize.underscore @record_select_config = RecordSelect::Config.new(.delete(:model), ) self.send :include, RecordSelect::Actions self.send :include, RecordSelect::Conditions end |
#uses_record_select? ⇒ Boolean
29 30 31 |
# File 'lib/record_select.rb', line 29 def uses_record_select? !record_select_config.nil? end |