Module: Rails::Trash::ClassMethods

Defined in:
lib/rails-trash.rb

Instance Method Summary collapse

Instance Method Details

#deleted(field = nil, value = nil) ⇒ Object



23
24
25
26
27
28
# File 'lib/rails-trash.rb', line 23

def deleted(field = nil, value = nil)
  deleted_at = Arel::Table.new(self.table_name)[:deleted_at]
  data = unscoped
  data = data.where(field => value) if field && value
  data.where(deleted_at.not_eq(nil))
end

#find_in_trash(id) ⇒ Object



30
31
32
# File 'lib/rails-trash.rb', line 30

def find_in_trash(id)
  deleted.find(id)
end

#restore(id) ⇒ Object



34
35
36
# File 'lib/rails-trash.rb', line 34

def restore(id)
  find_in_trash(id).restore
end