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
16
17
18
19
20
21
# File 'app/controllers/effective/trash_controller.rb', line 10

def index

  if Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
    @datatable = Effective::Datatables::Trash.new(user_id: current_user.id)
  else
    @datatable = EffectiveTrashDatatable.new(self, user_id: current_user.id)
  end

  @page_title = 'Trash'

  EffectiveTrash.authorized?(self, :index, Effective::Trash.new(user_id: current_user.id))
end

#restoreObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/effective/trash_controller.rb', line 31

def restore
  @trash = Effective::Trash.all.find(params[:id])
  EffectiveTrash.authorized?(self, :update, @trash)

  Effective::Trash.transaction do
    begin
      @trash.restore!
      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



24
25
26
27
28
29
# File 'app/controllers/effective/trash_controller.rb', line 24

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