diff options
Diffstat (limited to 'app/controllers/crops_controller.rb')
-rw-r--r-- | app/controllers/crops_controller.rb | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb new file mode 100644 index 0000000..9619852 --- /dev/null +++ b/app/controllers/crops_controller.rb @@ -0,0 +1,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 |