[Rails] Fertilizer recipe solver for the FAPG.
1
classNutrientProfilesController<ApplicationController
2
before_action :set_crop, only: %i[ show edit update destroy ]
3
4
defindex
5
@crops = Crop.all
6
end
7
8
defshow
9
end
10
11
defnew
12
@crop = Crop.new
13
end
14
15
defedit
16
end
17
18
defcreate
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
defupdate
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
defdestroy
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
defset_crop
52
@crop = Crop.find(params.expect(:id))
53
end
54
55
defcrop_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