Module: Redmine::Acts::Searchable::ClassMethods
- Defined in:
- lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb
Instance Method Summary collapse
-
#acts_as_searchable(options = {}) ⇒ Object
Adds the search methods to the class.
Instance Method Details
#acts_as_searchable(options = {}) ⇒ Object
Adds the search methods to the class.
Options:
-
:columns - a column or an array of columns to search
-
:project_key - project foreign key (default to project_id)
-
:date_column - name of the datetime column used to sort results (default to :created_on)
-
:permission - permission required to search the model
-
:scope - scope used to search results
-
:preload - associations to preload when loading results for display
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb', line 35 def acts_as_searchable( = {}) return if self.included_modules.include?(Redmine::Acts::Searchable::InstanceMethods) .assert_valid_keys(:columns, :project_key, :date_column, :permission, :scope, :preload) cattr_accessor :searchable_options self. = if [:columns].nil? raise 'No searchable column defined.' elsif ![:columns].is_a?(Array) [:columns] = [] << [:columns] end [:project_key] ||= "#{table_name}.project_id" [:date_column] ||= :created_on # Should we search additional associations on this model ? [:search_custom_fields] = reflect_on_association(:custom_values).present? [:search_attachments] = reflect_on_association(:attachments).present? [:search_journals] = reflect_on_association(:journals).present? send :include, Redmine::Acts::Searchable::InstanceMethods end |