Sha256: 097dd83b9763d176f832d66a2f9c1670d5c3fe67731999b3f0e1899550d6c430

Contents?: true

Size: 1.88 KB

Versions: 15

Compression:

Stored size: 1.88 KB

Contents

class ProductsController < ApplicationController
  before_action :set_product, only: [:show, :edit, :update, :destroy]

  # GET /products
  # GET /products.json
  def index
    @products = Product.all
  end

  # GET /products/1
  # GET /products/1.json
  def show
  end

  # GET /products/new
  def new
    @product = Product.new
  end

  # GET /products/1/edit
  def edit
  end

  # POST /products
  # POST /products.json
  def create
    @product = Product.new(product_params)

    respond_to do |format|
      if @product.save
        format.html { redirect_to @product, notice: 'Product was successfully created.' }
        format.json { render :show, status: :created, location: @product }
      else
        format.html { render :new }
        format.json { render json: @product.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /products/1
  # PATCH/PUT /products/1.json
  def update
    respond_to do |format|
      if @product.update(product_params)
        format.html { redirect_to @product, notice: 'Product was successfully updated.' }
        format.json { render :show, status: :ok, location: @product }
      else
        format.html { render :edit }
        format.json { render json: @product.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /products/1
  # DELETE /products/1.json
  def destroy
    @product.destroy
    respond_to do |format|
      format.html { redirect_to products_url, notice: 'Product was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

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

    # Never trust parameters from the scary internet, only allow the white list through.
    def product_params
      params.require(:product).permit(:name, :code, :price, :category_id)
    end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
restspec-0.3.2 examples/store-api/app/controllers/products_controller.rb
restspec-0.3.1 examples/store-api/app/controllers/products_controller.rb
restspec-0.3.0 examples/store-api/app/controllers/products_controller.rb
restspec-0.2.6 examples/store-api/app/controllers/products_controller.rb
restspec-0.2.5 examples/store-api/app/controllers/products_controller.rb
restspec-0.2.4 examples/store-api/app/controllers/products_controller.rb
restspec-0.2.3 examples/store-api/app/controllers/products_controller.rb
restspec-0.2.2 examples/store-api/app/controllers/products_controller.rb
restspec-0.2.1 examples/store-api/app/controllers/products_controller.rb
restspec-0.2 examples/store-api/app/controllers/products_controller.rb
restspec-0.1 examples/store-api/app/controllers/products_controller.rb
restspec-0.0.4 examples/store-api/app/controllers/products_controller.rb
restspec-0.0.3 examples/store-api/app/controllers/products_controller.rb
restspec-0.0.2 examples/store-api/app/controllers/products_controller.rb
restspec-0.0.1 examples/store-api/app/controllers/products_controller.rb