Forum: Ruby on Rails is_active?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Cf29a76768b845c5ce2a9aebade52aa1?d=identicon&s=25 roof jump (roofjump)
on 2007-05-11 21:09
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!
2f9a03aa0fcfe945229cb6126eda2cb2?d=identicon&s=25 Philip Hallstrom (Guest)
on 2007-05-11 21:35
(Received via mailing list)
> 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.
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2007-05-11 21:41
(Received via mailing list)
On 5/11/07, Philip Hallstrom <rails@philip.pjkh.com> 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 Olson
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
Cf29a76768b845c5ce2a9aebade52aa1?d=identicon&s=25 roof jump (roofjump)
on 2007-05-11 21:54
Thanks for the links guys!! I'll review both, and made a decision on
which way to go.
This topic is locked and can not be replied to.