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



6
7
8
9
10
11
12
# File 'app/controllers/effective/trash_controller.rb', line 6

def index
  @datatable = EffectiveTrashDatatable.new(self, user_id: current_user.id)

  @page_title = 'Trash'

  EffectiveResources.authorize!(self, :index, Effective::Trash.new(user_id: current_user.id))
end

#restoreObject



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

def restore
  @trash = Effective::Trash.find(params[:id])
  EffectiveResources.authorize!(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

  if request.referer.to_s.include?(effective_trash.admin_trash_index_path)
    redirect_to effective_trash.admin_trash_index_path
  else
    redirect_to effective_trash.trash_index_path
  end

end

#showObject

This is the User show event



15
16
17
18
19
20
# File 'app/controllers/effective/trash_controller.rb', line 15

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

  EffectiveResources.authorize!(self, :show, @trash)
end