Class: Effective::TrashController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/effective/trash_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject

This is the User index event



10
11
12
13
14
15
# File 'app/controllers/effective/trash_controller.rb', line 10

def index
  @datatable = Effective::Datatables::Trash.new(user_id: current_user.id)
  @page_title = 'Trash'

  EffectiveLogging.authorized?(self, :restore, Effective::Log.new(user_id: current_user.id))
end

#restoreObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/effective/trash_controller.rb', line 25

def restore
  @trash = Effective::Log.trash.find(params[:id])
  EffectiveLogging.authorized?(self, :restore, @trash)

  Effective::Log.transaction do
    begin
      @trash.restore_trashable!
      @trash.destroy!
      flash[:success] = "Successfully restored #{@trash}"
    rescue => e
      flash[:danger] = "Unable to restore: #{e.message}"
      raise ActiveRecord::Rollback
    end
  end

  redirect_back(fallback_location: effective_logging.trash_path)
end

#showObject

This is the User show event



18
19
20
21
22
23
# File 'app/controllers/effective/trash_controller.rb', line 18

def show
  @trash = Effective::Log.trash.find(params[:id])
  @page_title = "Trash item - #{@trash.to_s}"

  EffectiveLogging.authorized?(self, :restore, @trash)
end