Sha256: 895310f1a0f927be39f39728e665f539e2e2c53e7dad509d544a9f58d22f6fcf
Contents?: true
Size: 1.59 KB
Versions: 8
Compression:
Stored size: 1.59 KB
Contents
require_dependency "fly_admin/application_controller" # Categories = Serialss module FlyAdmin class CategoriesController < ApplicationController before_filter :set_category, only: [:create, :update, :destroy] def index @categories = Category.all end def create if @category.save flash[:notice] = "Сериал успешно создан " redirect_to categories_path else render 'new' end end def new @category = Category.new end def edit @category = Category.find(params[:id]) end def update if @category.update_attributes(category_params) flash[:notice] = "Сериал обновлен" redirect_to categories_path else render action: "edit" end end def destroy @category = Category.find(params[:id]) @category.destroy! flash[:notice] = "Сериал успешно удален" redirect_to categories_path end def seasons @category = Category.find(params[:category_id]) @seasons = @category.seasons.each {|s| s.json_title = JSON.parse(s.title)["ru"]} end private def category_params params.require(:category).permit! end def set_category if params[:id] @category = Category.find(params[:id]) else redirect_to new_category_path, alert: "Укажите хотя бы 1 сериал и 1 сезон" and return unless params["category"].present? @category = Category.new category_params end @category.name = params[:name] end end end
Version data entries
8 entries across 8 versions & 1 rubygems