View raw

1 class NutrientProfilesController < ApplicationController 2 before_action :set_crop, only: %i[ show edit update destroy ] 3 4 def index 5 @crops = Crop.all 6 end 7 8 def show 9 end 10 11 def new 12 @crop = Crop.new 13 end 14 15 def edit 16 end 17 18 def create 19 @crop = Crop.new(crop_params) 20 21 if @crop.save 22 redirect_to @crop, notice: "Crop was successfully created." 23 else 24 render :new, status: :unprocessable_entity 25 end 26 end 27 28 def update 29 respond_to do |format| 30 if @crop.update(crop_params) 31 format.html { redirect_to @crop, notice: "Crop was successfully updated.", status: :see_other } 32 format.json { render :show, status: :ok, location: @crop } 33 else 34 format.html { render :edit, status: :unprocessable_entity } 35 format.json { render json: @crop.errors, status: :unprocessable_entity } 36 end 37 end 38 end 39 40 def destroy 41 @crop.destroy! 42 43 respond_to do |format| 44 format.html { redirect_to crops_path, notice: "Crop was successfully destroyed.", status: :see_other } 45 format.json { head :no_content } 46 end 47 end 48 49 private 50 51 def set_crop 52 @crop = Crop.find(params.expect(:id)) 53 end 54 55 def crop_params 56 params.expect(crop: [ :name, :crop_type, :nno3, :p, :k, :ca, :mg, :s, :na, :cl, :si, :fe, :zn, :b, :mn, :cu, :mo, :nnh4 ]) 57 end 58 end 59