Exception: ActiveRecord::StaleObjectError

Inherits:
ActiveRecordError show all
Defined in:
activerecord/lib/active_record/errors.rb

Overview

Raised on attempt to save stale record. Record is stale when it’s being saved in another query after instantiation, for example, when two users edit the same wiki page and one starts editing and saves the page before the other.

Read more about optimistic locking in ActiveRecord::Locking module documentation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record = nil, attempted_action = nil) ⇒ StaleObjectError



387
388
389
390
391
392
393
394
395
# File 'activerecord/lib/active_record/errors.rb', line 387

def initialize(record = nil, attempted_action = nil)
  if record && attempted_action
    @record = record
    @attempted_action = attempted_action
    super("Attempted to #{attempted_action} a stale object: #{record.class.name}.")
  else
    super("Stale object error.")
  end
end

Instance Attribute Details

#attempted_actionObject (readonly)

Returns the value of attribute attempted_action.



385
386
387
# File 'activerecord/lib/active_record/errors.rb', line 385

def attempted_action
  @attempted_action
end

#recordObject (readonly)

Returns the value of attribute record.



385
386
387
# File 'activerecord/lib/active_record/errors.rb', line 385

def record
  @record
end