Class: IshManager::VideosController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ish_manager/videos_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#home

Instance Method Details

#createObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/ish_manager/videos_controller.rb', line 62

def create
  @video = Video.new params[:video].permit(%i| name descr is_public is_trash is_feature x y lang youtube_id
    tags city site user_profile premium_tier premium_purchases thumb video |)
  @video. = current_user.profile
  if !params[:video][:site_id].blank?
    @video.site = Site.find params[:video][:site_id]
    @video.site.touch
  else
    if @site
      @video.site = @site
      @site.touch
    end
  end
  authorize! :create, @video

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

#destroyObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/controllers/ish_manager/videos_controller.rb', line 112

def destroy
  @video = Video.unscoped.find params[:id]
  authorize! :destroy, @video
  flag = @video.update_attributes( :is_trash => true )
  @video.city.touch if @video.city
  @video.site.touch if @video.site
  @video.tags.map &:touch
  if flag
    flash[:notice] = "deleted video"
  else
    flash[:alert] = "Cannot delete video: #{@video.errors.messages}"
  end
  redirect_to :action => 'index'
end

#editObject



88
89
90
91
92
93
94
95
# File 'app/controllers/ish_manager/videos_controller.rb', line 88

def edit
  @video = Video.unscoped.find params[:id]
  @user_profiles_list = IshModels::UserProfile.list
  authorize! :edit, @video

  @tags_list = Tag.unscoped.or( { :is_public => true }, { :user_id => current_user.id } ).list
  @cities_list = City.list
end

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/ish_manager/videos_controller.rb', line 6

def index
  authorize! :index, Video.new
  @videos = Video.unscoped.where( is_trash: false, :user_profile => current_user.profile ).order_by( :created_at => :desc )

  if params[:city_id]
    city = City.find params[:city_id]
    @videos = @videos.where( :city => city )
  end

  if params[:tag_id]
    tag = Tag.find params[:tag_id]
    @videos = @videos.where( :tag => tag )
  end

  if params[:site_id]
    @site = Site.find params[:site_id]
    @videos = @site.videos
  end

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

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

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

#newObject



54
55
56
57
58
59
60
# File 'app/controllers/ish_manager/videos_controller.rb', line 54

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

  @tags_list = Tag.unscoped.or( { :is_public => true }, { :user_id => current_user.id } ).list
  @cities_list = City.list
end

#showObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/ish_manager/videos_controller.rb', line 41

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

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

#updateObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/controllers/ish_manager/videos_controller.rb', line 97

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

  @video.update params[:video].permit!
  if @video.save
    @video.site.touch if @video.site
    flash[:notice] = 'Success.'
    redirect_to videos_path
  else
    flash[:alert] = "No luck: #{@video.errors.messages}"
    render :edit
  end
end