default_scope と with_exclusive_scope

default_scopeを使うと論理削除を簡単に実現できる。たとえば論理削除したものは deleted_at に日時が入るという場合、

default_scope :conditions => ["deleted_at IS NOT NULL"]

とすると、論理削除されていないものだけが取得できる。

論理削除したものも取得したい場合は with_exclusive_scope を使う。

self.with_exclusive_scope do 
  self.all
end

とすると、全部が取得できる。