summaryrefslogtreecommitdiff
path: root/app/controllers/crops_controller.rb
blob: 9619852229503f09332c339f1dba1b31eb32712e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class CropsController < ApplicationController
  before_action :set_crop, only: %i[ show edit update destroy ]

  # GET /crops or /crops.json
  def index
    @crops = Crop.all
  end

  # GET /crops/1 or /crops/1.json
  def show
  end

  # GET /crops/new
  def new
    @crop = Crop.new
  end

  # GET /crops/1/edit
  def edit
  end

  # POST /crops or /crops.json
  def create
    @crop = Crop.new(crop_params)

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

  # PATCH/PUT /crops/1 or /crops/1.json
  def update
    respond_to do |format|
      if @crop.update(crop_params)
        format.html { redirect_to @crop, notice: "Crop was successfully updated.", status: :see_other }
        format.json { render :show, status: :ok, location: @crop }
      else
        format.html { render :edit, status: :unprocessable_entity }
        format.json { render json: @crop.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /crops/1 or /crops/1.json
  def destroy
    @crop.destroy!

    respond_to do |format|
      format.html { redirect_to crops_path, notice: "Crop was successfully destroyed.", status: :see_other }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_crop
      @crop = Crop.find(params.expect(:id))
    end

    # Only allow a list of trusted parameters through.
    def crop_params
      params.expect(crop: [ :name, :crop_type, :nno3, :p, :k, :ca, :mg, :s, :na, :cl, :si, :fe, :zn, :b, :mn, :cu, :mo, :nnh4 ])
    end
end
Copyright 2019--2025 Marius PETER