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'

  EffectiveTrash.authorized?(self, :index, Effective::Trash.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::Trash.all.find(params[:id])
  EffectiveTrash.authorized?(self, :update, @trash)

  Effective::Trash.transaction do
    begin
      @trash.restore_trash!
      @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_trash.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::Trash.where(user_id: current_user.id).find(params[:id])
  @page_title = "Trash item - #{@trash.to_s}"

  EffectiveTrash.authorized?(self, :show, @trash)
end