Sha256: 426288ec41dda2d93ff5123131ee8efabcb6cbcebde596ec60b3d14bed2a3df2

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

class CategoriesController < ApplicationController

  def index
    @categories = Category.all
    render :text => @categories.to_json
  end

  def new
    @category = Category.new
    @category.subcategories.build
  end

  def create
    @category = Category.new(params[:category])

    if @category.save
      redirect_to categories_path, :notice => 'The new category was successfully created'
    else
      @category.subcategories.build
      render 'new'
    end
  end

  def edit
    @category = Category.find(params[:id])
    @category.subcategories.build if @category.subcategories.blank?
  end

  def update
    @category = Category.find(params[:id])

    if @category.update_attributes(params[:category])
      redirect_to categories_path, :notice => 'The category was successfully updated'
    else
      @category.subcategories.build if @category.subcategories.blank?
      render :action => "edit"
    end
  end

  def destroy
    @category = Category.find(params[:id])

    @category.destroy
    redirect_to categories_path, :notice => "The category was successfully deleted"
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dynamic_fields-0.3.3 test/dummy/app/controllers/categories_controller.rb
dynamic_fields-0.3.2 test/dummy/app/controllers/categories_controller.rb
dynamic_fields-0.3.1 test/dummy/app/controllers/categories_controller.rb
dynamic_fields-0.3.0 test/dummy/app/controllers/categories_controller.rb
dynamic_fields-0.2.0 test/dummy/app/controllers/categories_controller.rb