Class: Wco::ReportsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/wco/reports_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#home, #tinymce

Methods included from ApplicationHelper

#my_truthy?, #obfuscate, #pp_amount, #pp_currency, #pp_date, #pp_datetime, #pp_money, #pp_percent, #pp_time, #pretty_date

Instance Method Details

#createObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/wco/reports_controller.rb', line 6

def create
  params[:report][:tag_ids]&.delete ''

  @report = Wco::Report.new params[:report].permit!
  authorize! :create, @report
  @report.author = current_profile
  if @report.save
    flash_notice "created report"
  else
    flash_alert "Cannot create report: #{@report.errors.messages}"
  end
  redirect_to action: 'index'
end

#destroyObject



20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/wco/reports_controller.rb', line 20

def destroy
  @report = Wco::Report.find params[:id]
  authorize! :destroy, @report
  if @report.destroy
    flash_notice 'ok'
  else
    flash_alert 'No luck.'
  end
  redirect_to action: 'index'
end

#editObject



31
32
33
34
# File 'app/controllers/wco/reports_controller.rb', line 31

def edit
  @report = Wco::Report.unscoped.find params[:id]
  authorize! :edit, @report
end

#indexObject



36
37
38
39
40
41
42
# File 'app/controllers/wco/reports_controller.rb', line 36

def index
  authorize! :index, Wco::Report
  @reports = Wco::Report.all.page( params[:reports_page] ).per( current_profile.per_page )
  if params[:deleted]
    @reports = Wco::Report.unscoped.where( :deleted_at.ne => nil )
  end
end

#newObject



44
45
46
47
# File 'app/controllers/wco/reports_controller.rb', line 44

def new
  authorize! :new, Wco::Report
  @new_report = Wco::Report.new
end

#showObject



49
50
51
52
# File 'app/controllers/wco/reports_controller.rb', line 49

def show
  @report = Wco::Report.unscoped.find params[:id]
  authorize! :show, @report
end

#updateObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/wco/reports_controller.rb', line 54

def update
  params[:report][:tag_ids]&.delete ''

  @report = Wco::Report.unscoped.find params[:id]
  authorize! :update, @report
  if @report.update params[:report].permit!
    flash_notice "updated report"
  else
    flash_alert "Cannot update report: #{@report.errors.messages}"
  end
  redirect_to action: 'index'
end