Class: Wco::VideosController
Instance Method Summary
collapse
#home, #tinymce
#my_truthy?, #obfuscate, #pp_amount, #pp_currency, #pp_date, #pp_datetime, #pp_money, #pp_percent, #pp_time, #pretty_date
Instance Method Details
#create ⇒ Object
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
|
#destroy ⇒ Object
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
|
#edit ⇒ Object
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
|
#index ⇒ Object
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
|
#new ⇒ Object
71
72
73
74
|
# File 'app/controllers/wco/videos_controller.rb', line 71
def new
@video = Wco::Video.new
authorize! :new, @video
end
|
#show ⇒ Object
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
|
#update ⇒ Object
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
@video.update params[:video].permit!
if @video.save
flash[:notice] = 'Success.'
redirect_to video_path(@video)
else
flash[:alert] = "No luck: #{@video.errors.full_messages.join(', ')}"
render :edit
end
end
|