C
C. Dagnon
I'm pretty mystified by this, so I would appreciate any insights...
This does involve a Rails/ActiveRecord object, but that shouldn't matter
here, right?
I'm archiving an object when it gets deleted, so I'm chaining methods in
a Rails controller:
triplet.archive(@user.id).as_delete.save
But I checked the database and the flag never got reset from false. I
added some print statements to as_delete() to get this:
class ArchiveTriplet < ActiveRecord::Base
def as_delete
puts "MARKING: #{is_deleted}"
is_deleted = true
puts "MARKED: #{is_deleted}/#{self.is_deleted}"
return self
end
end
With an additional debug after as_delete() the log shows:
MARKING: false
MARKED: true/false
ARCHIVING: #[ArchiveTriplet..., is_deleted: false, ...]
What?!
The easy solution is to change is_deleted everywhere to self.is_deleted,
but am I misunderstanding what 'self' is supposed to be? Is there
another keyword which means what I've been lead to believe 'self' should
mean? (ie. 'this' in Java)
Thanks,
-Chris
using: ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
This does involve a Rails/ActiveRecord object, but that shouldn't matter
here, right?
I'm archiving an object when it gets deleted, so I'm chaining methods in
a Rails controller:
triplet.archive(@user.id).as_delete.save
But I checked the database and the flag never got reset from false. I
added some print statements to as_delete() to get this:
class ArchiveTriplet < ActiveRecord::Base
def as_delete
puts "MARKING: #{is_deleted}"
is_deleted = true
puts "MARKED: #{is_deleted}/#{self.is_deleted}"
return self
end
end
With an additional debug after as_delete() the log shows:
MARKING: false
MARKED: true/false
ARCHIVING: #[ArchiveTriplet..., is_deleted: false, ...]
What?!
The easy solution is to change is_deleted everywhere to self.is_deleted,
but am I misunderstanding what 'self' is supposed to be? Is there
another keyword which means what I've been lead to believe 'self' should
mean? (ie. 'this' in Java)
Thanks,
-Chris
using: ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]