Class: Journal
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Journal
- Defined in:
- app/models/journal.rb
Class Method Summary (collapse)
Class Method Details
+ (Object) import(name)
7 8 9 10 11 12 |
# File 'app/models/journal.rb', line 7 def self.import name return unless name.present? journal = find_or_create_by_name name raise unless journal.valid? journal end |
+ (Object) search(term = '')
14 15 16 17 18 19 20 21 22 |
# File 'app/models/journal.rb', line 14 def self.search term = '' search_expression = term.split('').join('%') + '%' select('journals.name, COUNT(*)'). joins('LEFT OUTER JOIN `references` ON references.journal_id = journals.id'). where('journals.name LIKE ?', search_expression). group('journals.id'). order('COUNT(*) DESC'). map(&:name) end |