Sha256: efdbf9597466c43449f6d501ec7712837e66aaa27ce43f9df1818a40537d5c26

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

class CategoriesController < ApplicationController
  before_action :set_category, only: [:show, :edit, :update, :destroy]

  # GET /categories
  def index
    @categories = Category.all
  end

  # GET /categories/1
  def show
  end

  # GET /categories/new
  def new
    @category = Category.new
  end

  # GET /categories/1/edit
  def edit
  end

  # POST /categories
  def create
    @category = Category.new(category_params)

    if @category.save
      redirect_to @category, notice: 'Category was successfully created.'
    else
      render :new
    end
  end

  # PATCH/PUT /categories/1
  def update
    if @category.update(category_params)
      redirect_to @category, notice: 'Category was successfully updated.'
    else
      render :edit
    end
  end

  # DELETE /categories/1
  def destroy
    @category.destroy
    redirect_to categories_url, notice: 'Category was successfully destroyed.'
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_category
      @category = Category.find(params[:id])
    end

    # Only allow a trusted parameter "white list" through.
    def category_params
      params.require(:category).permit(:title)
    end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
adminish-0.0.1 test/dummy/app/controllers/categories_controller.rb
metaslug-0.3.5 test/dummy/app/controllers/categories_controller.rb
metaslug-0.3.4 test/dummy/app/controllers/categories_controller.rb
metaslug-0.3.3 test/dummy/app/controllers/categories_controller.rb