require_dependency "fly_admin/application_controller" module FlyAdmin class VideosController < ApplicationController before_action :set_video, only: [:show, :edit, :update, :destroy] before_action :set_categories, only: [:index] # GET /videos def index if request.post? || redirected_after_uploading? filter_results end end # GET /videos/1 def show end # GET /videos/new def new @video = Video.new end # GET /videos/1/edit def edit end # POST /videos def create @video = Video.new(video_params) if @video.save redirect_to @video, notice: 'Video was successfully created.' else render :new end end # PATCH/PUT /videos/1 def update if @video.update(video_params) redirect_to @video, notice: 'Video was successfully updated.' else render :edit end end # DELETE /videos/1 def destroy @video.destroy redirect_to videos_url, notice: 'Видео успешно удалено!!!!' end private # Use callbacks to share common setup or constraints between actions. def set_video @video = Video.find(params[:id]) end # Only allow a trusted parameter "white list" through. def video_params params[:video] end def set_categories @categories = Category.all.each {|c| c.json_name = JSON.parse(c.name)["ru"]} end def filter_results season_id = params["season"].try(:[], "season_id") || params["season_id"] redirect_to videos_path, alert: "Пожалуйста укажите сезон" and return unless season_id.present? @season = Season.find(season_id) # needed for filter select @category = @season.category @seasons = @category.seasons.each {|s| s.json_title = JSON.parse(s.title)["ru"]} # needed for videos list @videos = @season.videos end def redirected_after_uploading? params["after_upload"].present? end end end