Class: IshManager::VideosController
Instance Method Summary
collapse
#basic_auth, #home, #tinymce
Instance Method Details
#create ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'app/controllers/ish_manager/videos_controller.rb', line 8
def create
@video = Video.new params[:video].permit(%i| name descr is_public is_trash is_feature x y lang youtube_id
site user_profile premium_tier premium_purchases thumb video |)
@video.user_profile = @current_profile
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
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/controllers/ish_manager/videos_controller.rb', line 23
def destroy
@video = Video.unscoped.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
35
36
37
38
39
|
# File 'app/controllers/ish_manager/videos_controller.rb', line 35
def edit
@video = Video.unscoped.find params[:id]
@user_profiles_list = Ish::UserProfile.list
authorize! :edit, @video
end
|
#index ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'app/controllers/ish_manager/videos_controller.rb', line 41
def index
authorize! :index, Video.new
@videos = Video.unscoped.where({
is_trash: false,
}).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 do
render
end
format.json do
render :json => @videos
end
end
end
|
#new ⇒ Object
77
78
79
80
|
# File 'app/controllers/ish_manager/videos_controller.rb', line 77
def new
@video = Video.new
authorize! :new, @video
end
|
#show ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'app/controllers/ish_manager/videos_controller.rb', line 64
def show
@video = Video.unscoped.where( :youtube_id => params[:youtube_id] ).first if params[:youtube_id].present?
@video ||= 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'app/controllers/ish_manager/videos_controller.rb', line 82
def update
@video = 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
flash[:notice] = 'Success.'
redirect_to video_path(@video)
else
flash[:alert] = "No luck: #{@video.errors.messages}"
render :edit
end
end
|