Hey all, i’m rather new to rails and was curious if ActiveRecord
implemented anything like is_active where the delete functions would
just mark records as inactive, vs deleting rows. (similar to created_at,
etc). I need a history of transactions, and this is how I would code in
other languages. Any advice? Is there are smarter way to implement this?
Thanks in advance!
Hey all, i’m rather new to rails and was curious if ActiveRecord
implemented anything like is_active where the delete functions would
just mark records as inactive, vs deleting rows. (similar to created_at,
etc). I need a history of transactions, and this is how I would code in
other languages. Any advice? Is there are smarter way to implement this?
http://agilewebdevelopment.com/plugins/acts_as_paranoid
Make your Active Records “paranoid.” Deleting them does not delete the
row, but set a deleted_at field. Find is overloaded to skip deleted
records.
On 5/11/07, Philip H. [email protected] wrote:
row, but set a deleted_at field. Find is overloaded to skip deleted
records.
I’d say keep it more explicit and use the scope_out plugin:
http://www.dcmanges.com/blog/21
class Foo < AR::Base
scope_out :enabled, :conditions => ‘disabled_at is null’
def enabled?
disabled_at.nil?
end
def disabled?
!enabled?
end
def disable
update_attribute :disabled_at, Time.now.utc
end
end
Foo.find_enabled(:all, :limit => 30, :offset => 60).each do |foo|
end
–
Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
Thanks for the links guys!! I’ll review both, and made a decision on
which way to go.