class IshManager::VideosController < IshManager::ApplicationController before_action :set_lists def index authorize! :index, Video.new @videos = Video.unscoped 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 respond_to do |format| format.html do render end format.json do render :json => @videos end end end 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 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 def create @video = Video.new params[:video].permit! @video.user = current_user if params[:video][:site_id] @video.site = Site.find params[:video][:site_id] @video.site.touch else @video.site = @site @site.touch end authorize! :create, @video if @video.save flash[:notice] = 'Success' redirect_to videos_path else flash[:error] = 'No luck' @tags_list = Tag.list @cities_list = City.list render :action => 'new' end end def edit @video = Video.unscoped.find params[:id] authorize! :edit, @video @tags_list = Tag.unscoped.or( { :is_public => true }, { :user_id => current_user.id } ).list @cities_list = City.list end 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[:error] = "No luck: #{@video.errors}" render :edit end end 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.tag.touch if @video.tag if flag flash[:notice] = "deleted video" else flash[:alert] = "Cannot delete video: #{@video.errors.messages}" end redirect_to :action => 'index' end end