Class: Wco::VideosController

Inherits:
ApplicationController show all
Defined in:
app/controllers/wco/videos_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

Alphabetized : )



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

def create
  @video = Wco::Video.new params[:video].permit!
  authorize! :create, @video

  if @video.save
    flash[:notice] = 'Success'
    redirect_to videos_path
  else
    flash[:alert] = 'No luck'
    render :action => 'new'
  end
end

#destroyObject



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

def destroy
  @video = Wco::Video.find params[:id]
  authorize! :destroy, @video
  flag = @video.delete
  if flag
    flash[:notice] = "deleted video"
  else
    flash[:alert] = "Cannot delete video: #{@video.errors.messages}"
  end
  redirect_to :action => 'index'
end

#editObject



33
34
35
36
# File 'app/controllers/wco/videos_controller.rb', line 33

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

#indexObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/wco/videos_controller.rb', line 38

def index
  authorize! :index, Wco::Video.new
  @videos = Wco::Video.order_by( :created_at => :desc )

  if params[:q]
    @videos = @videos.where({ :name => /#{params[:q]}/i })
  end

  @videos = @videos.page( params[:videos_page] ).per( 9 )

  respond_to do |format|
    format.html
    format.json do
      render :json => @videos
    end
  end
end

#newObject



71
72
73
74
# File 'app/controllers/wco/videos_controller.rb', line 71

def new
  @video = Wco::Video.new
  authorize! :new, @video
end

#showObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/wco/videos_controller.rb', line 56

def show
  if params[:youtube_id].present?
    @video = Wco::Video.unscoped.where( :youtube_id => params[:youtube_id] ).first
  end
  @video ||= Wco::Video.unscoped.find params[:id]
  authorize! :show, @video

  respond_to do |format|
    format.html
    format.json do
      render :json => @video
    end
  end
end

#updateObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/controllers/wco/videos_controller.rb', line 76

def update
  @video = Wco::Video.unscoped.find params[:id]
  authorize! :update, @video

  # old_shared_profile_ids = @video.shared_profile_ids
  # if params[:video][:shared_profiles].present?
  #   params[:video][:shared_profiles].delete('')
  # end
  # params[:video][:shared_profile_ids] = params[:video][:shared_profiles]
  # params[:video].delete :shared_profiles

  @video.update params[:video].permit!
  if @video.save

    # if params[:video][:shared_profile_ids].present?
    #   new_shared_profiles = Ish::UserProfile.find( params[:video][:shared_profile_ids]
    #     ).select { |p| !old_shared_profile_ids.include?( p.id ) }
    #   ::IshManager::ApplicationMailer.shared_video( new_shared_profiles, @video ).deliver
    # end

    flash[:notice] = 'Success.'
    redirect_to video_path(@video)
  else
    flash[:alert] = "No luck: #{@video.errors.full_messages.join(', ')}"
    render :edit
  end
end