From 7ad44b01adf8fba899051b1d2d0936e2bdff3141 Mon Sep 17 00:00:00 2001 From: Xero Date: Fri, 8 Mar 2024 14:51:46 -0500 Subject: [PATCH] fertilizer trackers setup --- .../fertilizer_trackers_controller.rb | 70 +++++++++++++++++++ app/helpers/fertilizer_trackers_helper.rb | 2 + app/helpers/fertlizer_trackers_helper.rb | 2 + app/models/fertilizer_tracker.rb | 2 + .../_fertilizer_tracker.html.erb | 7 ++ .../_fertilizer_tracker.json.jbuilder | 2 + app/views/fertilizer_trackers/_form.html.erb | 17 +++++ app/views/fertilizer_trackers/edit.html.erb | 8 +++ app/views/fertilizer_trackers/index.html.erb | 14 ++++ .../fertilizer_trackers/index.json.jbuilder | 1 + app/views/fertilizer_trackers/new.html.erb | 7 ++ app/views/fertilizer_trackers/show.html.erb | 15 ++++ .../fertilizer_trackers/show.json.jbuilder | 1 + config/routes.rb | 1 + .../fertilizer_trackers_routing_spec.rb | 38 ++++++++++ test/fixtures/fertilizer_trackers.yml | 6 ++ 16 files changed, 193 insertions(+) create mode 100644 app/controllers/fertilizer_trackers_controller.rb create mode 100644 app/helpers/fertilizer_trackers_helper.rb create mode 100644 app/helpers/fertlizer_trackers_helper.rb create mode 100644 app/models/fertilizer_tracker.rb create mode 100644 app/views/fertilizer_trackers/_fertilizer_tracker.html.erb create mode 100644 app/views/fertilizer_trackers/_fertilizer_tracker.json.jbuilder create mode 100644 app/views/fertilizer_trackers/_form.html.erb create mode 100644 app/views/fertilizer_trackers/edit.html.erb create mode 100644 app/views/fertilizer_trackers/index.html.erb create mode 100644 app/views/fertilizer_trackers/index.json.jbuilder create mode 100644 app/views/fertilizer_trackers/new.html.erb create mode 100644 app/views/fertilizer_trackers/show.html.erb create mode 100644 app/views/fertilizer_trackers/show.json.jbuilder create mode 100644 spec/routing/fertilizer_trackers_routing_spec.rb create mode 100644 test/fixtures/fertilizer_trackers.yml diff --git a/app/controllers/fertilizer_trackers_controller.rb b/app/controllers/fertilizer_trackers_controller.rb new file mode 100644 index 0000000..0d05d8f --- /dev/null +++ b/app/controllers/fertilizer_trackers_controller.rb @@ -0,0 +1,70 @@ +class FertilizerTrackersController < ApplicationController + before_action :set_fertilizer_tracker, only: %i[ show edit update destroy ] + + # GET /fertilizer_trackers or /fertilizer_trackers.json + def index + @fertilizer_trackers = FertilizerTracker.all + end + + # GET /fertilizer_trackers/1 or /fertilizer_trackers/1.json + def show + end + + # GET /fertilizer_trackers/new + def new + @fertilizer_tracker = FertilizerTracker.new + end + + # GET /fertilizer_trackers/1/edit + def edit + end + + # POST /fertilizer_trackers or /fertilizer_trackers.json + def create + @fertilizer_tracker = FertilizerTracker.new(fertilizer_tracker_params) + + respond_to do |format| + if @fertilizer_tracker.save + format.html { redirect_to fertilizer_tracker_url(@fertilizer_tracker), notice: "Fertilizer tracker was successfully created." } + format.json { render :show, status: :created, location: @fertilizer_tracker } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @fertilizer_tracker.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /fertilizer_trackers/1 or /fertilizer_trackers/1.json + def update + respond_to do |format| + if @fertilizer_tracker.update(fertilizer_tracker_params) + format.html { redirect_to fertilizer_tracker_url(@fertilizer_tracker), notice: "Fertilizer tracker was successfully updated." } + format.json { render :show, status: :ok, location: @fertilizer_tracker } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @fertilizer_tracker.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /fertilizer_trackers/1 or /fertilizer_trackers/1.json + def destroy + @fertilizer_tracker.destroy + + respond_to do |format| + format.html { redirect_to fertilizer_trackers_url, notice: "Fertilizer tracker was successfully destroyed." } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_fertilizer_tracker + @fertilizer_tracker = FertilizerTracker.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def fertilizer_tracker_params + params.fetch(:fertilizer_tracker, {}) + end +end diff --git a/app/helpers/fertilizer_trackers_helper.rb b/app/helpers/fertilizer_trackers_helper.rb new file mode 100644 index 0000000..db31a9f --- /dev/null +++ b/app/helpers/fertilizer_trackers_helper.rb @@ -0,0 +1,2 @@ +module FertilizerTrackersHelper +end diff --git a/app/helpers/fertlizer_trackers_helper.rb b/app/helpers/fertlizer_trackers_helper.rb new file mode 100644 index 0000000..4f5dab0 --- /dev/null +++ b/app/helpers/fertlizer_trackers_helper.rb @@ -0,0 +1,2 @@ +module FertlizerTrackersHelper +end diff --git a/app/models/fertilizer_tracker.rb b/app/models/fertilizer_tracker.rb new file mode 100644 index 0000000..286af11 --- /dev/null +++ b/app/models/fertilizer_tracker.rb @@ -0,0 +1,2 @@ +class FertilizerTracker < ApplicationRecord +end diff --git a/app/views/fertilizer_trackers/_fertilizer_tracker.html.erb b/app/views/fertilizer_trackers/_fertilizer_tracker.html.erb new file mode 100644 index 0000000..2db55a3 --- /dev/null +++ b/app/views/fertilizer_trackers/_fertilizer_tracker.html.erb @@ -0,0 +1,7 @@ +
+ <% if action_name != "show" %> + <%= link_to "Show this fertilizer tracker", fertilizer_tracker, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> + <%= link_to 'Edit this fertilizer tracker', edit_fertilizer_tracker_path(fertilizer_tracker), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %> +
+ <% end %> +
diff --git a/app/views/fertilizer_trackers/_fertilizer_tracker.json.jbuilder b/app/views/fertilizer_trackers/_fertilizer_tracker.json.jbuilder new file mode 100644 index 0000000..583867b --- /dev/null +++ b/app/views/fertilizer_trackers/_fertilizer_tracker.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! fertilizer_tracker, :id, :created_at, :updated_at +json.url fertilizer_tracker_url(fertilizer_tracker, format: :json) diff --git a/app/views/fertilizer_trackers/_form.html.erb b/app/views/fertilizer_trackers/_form.html.erb new file mode 100644 index 0000000..fb9ac81 --- /dev/null +++ b/app/views/fertilizer_trackers/_form.html.erb @@ -0,0 +1,17 @@ +<%= form_with(model: fertilizer_tracker, class: "contents") do |form| %> + <% if fertilizer_tracker.errors.any? %> +
+

<%= pluralize(fertilizer_tracker.errors.count, "error") %> prohibited this fertilizer_tracker from being saved:

+ + +
+ <% end %> + +
+ <%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> +
+<% end %> diff --git a/app/views/fertilizer_trackers/edit.html.erb b/app/views/fertilizer_trackers/edit.html.erb new file mode 100644 index 0000000..6833d3f --- /dev/null +++ b/app/views/fertilizer_trackers/edit.html.erb @@ -0,0 +1,8 @@ +
+

Editing fertilizer tracker

+ + <%= render "form", fertilizer_tracker: @fertilizer_tracker %> + + <%= link_to "Show this fertilizer tracker", @fertilizer_tracker, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> + <%= link_to "Back to fertilizer trackers", fertilizer_trackers_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +
diff --git a/app/views/fertilizer_trackers/index.html.erb b/app/views/fertilizer_trackers/index.html.erb new file mode 100644 index 0000000..8a7da0c --- /dev/null +++ b/app/views/fertilizer_trackers/index.html.erb @@ -0,0 +1,14 @@ +
+ <% if notice.present? %> +

<%= notice %>

+ <% end %> + +
+

Fertilizer trackers

+ <%= link_to 'New fertilizer tracker', new_fertilizer_tracker_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %> +
+ +
+ <%= render @fertilizer_trackers %> +
+
diff --git a/app/views/fertilizer_trackers/index.json.jbuilder b/app/views/fertilizer_trackers/index.json.jbuilder new file mode 100644 index 0000000..b59d9c9 --- /dev/null +++ b/app/views/fertilizer_trackers/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @fertilizer_trackers, partial: "fertilizer_trackers/fertilizer_tracker", as: :fertilizer_tracker diff --git a/app/views/fertilizer_trackers/new.html.erb b/app/views/fertilizer_trackers/new.html.erb new file mode 100644 index 0000000..3039ad5 --- /dev/null +++ b/app/views/fertilizer_trackers/new.html.erb @@ -0,0 +1,7 @@ +
+

New fertilizer tracker

+ + <%= render "form", fertilizer_tracker: @fertilizer_tracker %> + + <%= link_to 'Back to fertilizer trackers', fertilizer_trackers_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +
diff --git a/app/views/fertilizer_trackers/show.html.erb b/app/views/fertilizer_trackers/show.html.erb new file mode 100644 index 0000000..3c5fb37 --- /dev/null +++ b/app/views/fertilizer_trackers/show.html.erb @@ -0,0 +1,15 @@ +
+
+ <% if notice.present? %> +

<%= notice %>

+ <% end %> + + <%= render @fertilizer_tracker %> + + <%= link_to 'Edit this fertilizer_tracker', edit_fertilizer_tracker_path(@fertilizer_tracker), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +
+ <%= button_to 'Destroy this fertilizer_tracker', fertilizer_tracker_path(@fertilizer_tracker), method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %> +
+ <%= link_to 'Back to fertilizer_trackers', fertilizer_trackers_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +
+
diff --git a/app/views/fertilizer_trackers/show.json.jbuilder b/app/views/fertilizer_trackers/show.json.jbuilder new file mode 100644 index 0000000..553c1a1 --- /dev/null +++ b/app/views/fertilizer_trackers/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "fertilizer_trackers/fertilizer_tracker", fertilizer_tracker: @fertilizer_tracker diff --git a/config/routes.rb b/config/routes.rb index 3ff7d33..0f3e71d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :fertilizer_trackers resources :genera resources :plants resources :families diff --git a/spec/routing/fertilizer_trackers_routing_spec.rb b/spec/routing/fertilizer_trackers_routing_spec.rb new file mode 100644 index 0000000..c5f19bc --- /dev/null +++ b/spec/routing/fertilizer_trackers_routing_spec.rb @@ -0,0 +1,38 @@ +require "rails_helper" + +RSpec.describe FertilizerTrackersController, type: :routing do + describe "routing" do + it "routes to #index" do + expect(get: "/fertilizer_trackers").to route_to("fertilizer_trackers#index") + end + + it "routes to #new" do + expect(get: "/fertilizer_trackers/new").to route_to("fertilizer_trackers#new") + end + + it "routes to #show" do + expect(get: "/fertilizer_trackers/1").to route_to("fertilizer_trackers#show", id: "1") + end + + it "routes to #edit" do + expect(get: "/fertilizer_trackers/1/edit").to route_to("fertilizer_trackers#edit", id: "1") + end + + + it "routes to #create" do + expect(post: "/fertilizer_trackers").to route_to("fertilizer_trackers#create") + end + + it "routes to #update via PUT" do + expect(put: "/fertilizer_trackers/1").to route_to("fertilizer_trackers#update", id: "1") + end + + it "routes to #update via PATCH" do + expect(patch: "/fertilizer_trackers/1").to route_to("fertilizer_trackers#update", id: "1") + end + + it "routes to #destroy" do + expect(delete: "/fertilizer_trackers/1").to route_to("fertilizer_trackers#destroy", id: "1") + end + end +end diff --git a/test/fixtures/fertilizer_trackers.yml b/test/fixtures/fertilizer_trackers.yml new file mode 100644 index 0000000..a668f59 --- /dev/null +++ b/test/fixtures/fertilizer_trackers.yml @@ -0,0 +1,6 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + id: 1 + name: GigaFertilizer + date: today