Module: Moribus::Extensions::HasCurrentExtension

Defined in:
lib/moribus/extensions/has_current_extension.rb

Overview

Minor extension for Rails’ has_one association that will help dealing with current record assignment.

Instance Method Summary collapse

Instance Method Details

#remove_target!Object

Sets ‘is_current’ flag of overridden record to false, instead of deleting it or setting foreign key to nil.



8
9
10
11
12
13
14
# File 'lib/moribus/extensions/has_current_extension.rb', line 8

def remove_target!(*)
  if target.new_record?
    target.is_current = false
  else
    target.update_attribute(:is_current, false)
  end
end