Sha256: 65db7ce217a70427e798765cd08d917f07b9f0489e21341033f7fe788c8c624a

Contents?: true

Size: 1.32 KB

Versions: 7

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

# Controller for Ingredients, like "Mushrooms"
class IngredientsController < ApplicationController
  before_action :set_ingredient, only: %i[show edit update destroy]

  # GET /ingredients
  def index
    @ingredients = Ingredient.all
  end

  # GET /ingredients/1
  def show; end

  # GET /ingredients/new
  def new
    @ingredient = Ingredient.new
  end

  # GET /ingredients/1/edit
  def edit; end

  # POST /ingredients
  def create
    @ingredient = Ingredient.new(ingredient_params)

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

  # PATCH/PUT /ingredients/1
  def update
    if @ingredient.update(ingredient_params)
      redirect_to @ingredient, notice: 'Ingredient was successfully updated.'
    else
      render :edit
    end
  end

  # DELETE /ingredients/1
  def destroy
    @ingredient.destroy
    redirect_to ingredients_url, notice: 'Ingredient was successfully destroyed.'
  end

  private

  # Use callbacks to share common setup or constraints between actions.
  def set_ingredient
    @ingredient = Ingredient.find(params[:id])
  end

  # Only allow a list of trusted parameters through.
  def ingredient_params
    params.require(:ingredient).permit(:name, :description, :aisle, :store, :cost)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
cookbook-0.1.6 spec/dummy/app/controllers/ingredients_controller.rb
cookbook-0.1.5 spec/dummy/app/controllers/ingredients_controller.rb
cookbook-0.1.4 spec/dummy/app/controllers/ingredients_controller.rb
cookbook-0.1.3 spec/dummy/app/controllers/ingredients_controller.rb
cookbook-0.1.2 spec/dummy/app/controllers/ingredients_controller.rb
cookbook-0.1.1 spec/dummy/app/controllers/ingredients_controller.rb
cookbook-0.1.0 spec/dummy/app/controllers/ingredients_controller.rb