diff options
Diffstat (limited to 'app/controllers/crops_controller.rb')
-rw-r--r-- | app/controllers/crops_controller.rb | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index 9619852..951d380 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -1,40 +1,30 @@ 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 + if @crop.save + redirect_to @crop, notice: "Crop was successfully created." + else + render :new, status: :unprocessable_entity end end - # PATCH/PUT /crops/1 or /crops/1.json def update respond_to do |format| if @crop.update(crop_params) @@ -47,7 +37,6 @@ class CropsController < ApplicationController end end - # DELETE /crops/1 or /crops/1.json def destroy @crop.destroy! @@ -58,13 +47,12 @@ class CropsController < ApplicationController 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 + def set_crop + @crop = Crop.find(params.expect(:id)) + end + + 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 |