Class: Wco::NewspartialsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Wco::NewspartialsController
- Defined in:
- app/controllers/wco/newspartials_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #generate_speech ⇒ Object
- #generate_video ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
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! :create, @newspartial if @newspartial.save flash_notice "created newspartial" else flash_alert "Cannot create newspartial: #{@newspartial.errors.}" end redirect_to controller: 'newsvideos', id: @newspartial.newsvideo_id, action: 'show' end |
#destroy ⇒ Object
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] :destroy, @newspartial if @newspartial.destroy flash_notice 'ok' else flash_alert 'No luck.' end redirect_to request.referrer end |
#edit ⇒ Object
31 32 33 34 |
# File 'app/controllers/wco/newspartials_controller.rb', line 31 def edit @newspartial = Wco::Newspartial.unscoped.find params[:id] :edit, @newspartial end |
#generate_speech ⇒ Object
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] :show, @newspartial @newspartial.generate_speech redirect_to controller: 'newsvideos', id: @newspartial.newsvideo_id, action: 'show' end |
#generate_video ⇒ Object
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] :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 |
#index ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'app/controllers/wco/newspartials_controller.rb', line 55 def index :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 |
#new ⇒ Object
64 65 66 67 |
# File 'app/controllers/wco/newspartials_controller.rb', line 64 def new :new, Wco::Newspartial @newspartial = Wco::Newspartial.new end |
#show ⇒ Object
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] :show, @newspartial # @config = JSON.parse( @newspartial.config_json ) # @duration_ms = @config['vtimes'].last.to_i + @config['vdurations'].last.to_i end |
#update ⇒ Object
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] :update, @newspartial if @newspartial.update params[:newspartial].permit! flash_notice "updated newspartial" else flash_alert "Cannot update newspartial: #{@newspartial.errors.}" end redirect_to newsvideo_path(@newspartial.newsvideo_id) end |