Class: Wco::NewspartialsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#home, #tinymce

Methods included from ApplicationHelper

#my_truthy?, #obfuscate, #pexels_search_path, #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/newspartials_controller.rb', line 6

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

  @newspartial = Wco::Newspartial.new params[:newspartial].permit!
  authorize! :create, @newspartial

  if @newspartial.save
    flash_notice "created newspartial"
  else
    flash_alert "Cannot create newspartial: #{@newspartial.errors.messages}"
  end
  redirect_to controller: 'newsvideos', id: @newspartial.newsvideo_id, action: 'show'
end

#destroyObject



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

def destroy
  @newspartial = Wco::Newspartial.find params[:id]
  authorize! :destroy, @newspartial
  if @newspartial.destroy
    flash_notice 'ok'
  else
    flash_alert 'No luck.'
  end
  redirect_to request.referrer
end

#editObject



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

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

#generate_speechObject



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

def generate_speech
  @newspartial = Wco::Newspartial.unscoped.find params[:id]
  authorize! :show, @newspartial
  @newspartial.generate_speech
  redirect_to controller: 'newsvideos', id: @newspartial.newsvideo_id, action: 'show'
end

#generate_videoObject



43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/wco/newspartials_controller.rb', line 43

def generate_video
  @newspartial = Wco::Newspartial.unscoped.find params[:id]
  authorize! :edit, @newspartial

  Rails.env.production? ?
    Wco::NewspartialVideoJob.perform_async(params[:id]) :
    Wco::NewspartialVideoJob.perform_sync( params[:id])

  flash_notice 'Scheduled.'
  redirect_to controller: 'newsvideos', id: @newspartial.newsvideo_id, action: 'show'
end

#indexObject



55
56
57
58
59
60
61
62
# File 'app/controllers/wco/newspartials_controller.rb', line 55

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

#newObject



64
65
66
67
# File 'app/controllers/wco/newspartials_controller.rb', line 64

def new
  authorize! :new, Wco::Newspartial
  @newspartial = Wco::Newspartial.new
end

#showObject



69
70
71
72
73
74
75
# File 'app/controllers/wco/newspartials_controller.rb', line 69

def show
  @newspartial = Wco::Newspartial.unscoped.find params[:id]
  authorize! :show, @newspartial

  # @config = JSON.parse( @newspartial.config_json )
  # @duration_ms = @config['vtimes'].last.to_i + @config['vdurations'].last.to_i
end

#updateObject



77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/controllers/wco/newspartials_controller.rb', line 77

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

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