Files
old-stazarucak/whatforlunch.com/app/controllers/recipes_controller.rb
2017-09-24 10:12:44 +02:00

72 lines
1.6 KiB
Ruby

class RecipesController < ApplicationController
before_action :set_recipe, only: [:show, :edit, :update, :destroy]
# GET /recipes
# GET /recipes.json
def index
@recipes = Recipe.all
end
# GET /recipes/1
# GET /recipes/1.json
def show
end
# GET /recipes/new
def new
@recipe = Recipe.new
end
# GET /recipes/1/edit
def edit
@samplepis
end
# POST /recipes
def create
@recipe = Recipe.new(recipe_params)
@recipe.scrape!
respond_to do |format|
if @recipe.save
format.html { redirect_to edit_recipe_path(@recipe), notice: 'Recipe was successfully created.' }
else
format.html { render action: 'new' }
end
end
end
# PATCH/PUT /recipes/1
# PATCH/PUT /recipes/1.json
def update
respond_to do |format|
if @recipe.update(recipe_params)
format.html { render action: 'edit', notice: 'Recipe was successfully updated.' }
format.json { head :no_content }
format.html { render action: 'edit' }
end
end
end
# DELETE /recipes/1
# DELETE /recipes/1.json
def destroy
@recipe.destroy
respond_to do |format|
format.html { redirect_to recipes_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_recipe
@recipe = Recipe.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def recipe_params
params.require(:recipe).permit(:name, :duration, :ingredients, :process, :picture_url, :original_url)
end
end