Class: Searchjoy::Search
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Searchjoy::Search
- Defined in:
- app/models/searchjoy/search.rb
Instance Method Summary collapse
Instance Method Details
#convert(convertable = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/searchjoy/search.rb', line 11 def convert(convertable = nil) return unless Searchjoy.multiple_conversions || !converted? # use transaction to keep consistent self.class.transaction do # make time consistent now = Time.now if Searchjoy.multiple_conversions conversion = conversions.create!( convertable: convertable, created_at: now ) end unless converted? self.converted_at = now # check id instead of association self.convertable = convertable if respond_to?(:convertable_id=) save(validate: false) end conversion end end |
#converted? ⇒ Boolean
38 39 40 |
# File 'app/models/searchjoy/search.rb', line 38 def converted? converted_at.present? end |