Skip to content

Commit

Permalink
fertilizer trackers setup
Browse files Browse the repository at this point in the history
  • Loading branch information
one-m1nd committed Mar 8, 2024
1 parent 1a20e3a commit 7ad44b0
Show file tree
Hide file tree
Showing 16 changed files with 193 additions and 0 deletions.
70 changes: 70 additions & 0 deletions app/controllers/fertilizer_trackers_controller.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions app/helpers/fertilizer_trackers_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module FertilizerTrackersHelper
end
2 changes: 2 additions & 0 deletions app/helpers/fertlizer_trackers_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module FertlizerTrackersHelper
end
2 changes: 2 additions & 0 deletions app/models/fertilizer_tracker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class FertilizerTracker < ApplicationRecord
end
7 changes: 7 additions & 0 deletions app/views/fertilizer_trackers/_fertilizer_tracker.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div id="<%= dom_id fertilizer_tracker %>">
<% 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" %>
<hr class="mt-6">
<% end %>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! fertilizer_tracker, :id, :created_at, :updated_at
json.url fertilizer_tracker_url(fertilizer_tracker, format: :json)
17 changes: 17 additions & 0 deletions app/views/fertilizer_trackers/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= form_with(model: fertilizer_tracker, class: "contents") do |form| %>
<% if fertilizer_tracker.errors.any? %>
<div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg mt-3">
<h2><%= pluralize(fertilizer_tracker.errors.count, "error") %> prohibited this fertilizer_tracker from being saved:</h2>

<ul>
<% fertilizer_tracker.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="inline">
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
</div>
<% end %>
8 changes: 8 additions & 0 deletions app/views/fertilizer_trackers/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="mx-auto md:w-2/3 w-full">
<h1 class="font-bold text-4xl">Editing fertilizer tracker</h1>

<%= 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" %>
</div>
14 changes: 14 additions & 0 deletions app/views/fertilizer_trackers/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="w-full">
<% if notice.present? %>
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p>
<% end %>

<div class="flex justify-between items-center">
<h1 class="font-bold text-4xl">Fertilizer trackers</h1>
<%= link_to 'New fertilizer tracker', new_fertilizer_tracker_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %>
</div>

<div id="fertilizer_trackers" class="min-w-full">
<%= render @fertilizer_trackers %>
</div>
</div>
1 change: 1 addition & 0 deletions app/views/fertilizer_trackers/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @fertilizer_trackers, partial: "fertilizer_trackers/fertilizer_tracker", as: :fertilizer_tracker
7 changes: 7 additions & 0 deletions app/views/fertilizer_trackers/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="mx-auto md:w-2/3 w-full">
<h1 class="font-bold text-4xl">New fertilizer tracker</h1>

<%= 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" %>
</div>
15 changes: 15 additions & 0 deletions app/views/fertilizer_trackers/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="mx-auto md:w-2/3 w-full flex">
<div class="mx-auto">
<% if notice.present? %>
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p>
<% 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" %>
<div class="inline-block ml-2">
<%= 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" %>
</div>
<%= 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" %>
</div>
</div>
1 change: 1 addition & 0 deletions app/views/fertilizer_trackers/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "fertilizer_trackers/fertilizer_tracker", fertilizer_tracker: @fertilizer_tracker
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Rails.application.routes.draw do
resources :fertilizer_trackers
resources :genera
resources :plants
resources :families
Expand Down
38 changes: 38 additions & 0 deletions spec/routing/fertilizer_trackers_routing_spec.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions test/fixtures/fertilizer_trackers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
id: 1
name: GigaFertilizer
date: today

0 comments on commit 7ad44b0

Please sign in to comment.