-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module FertilizerTrackersHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module FertlizerTrackersHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class FertilizerTracker < ApplicationRecord | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
2 changes: 2 additions & 0 deletions
2
app/views/fertilizer_trackers/_fertilizer_tracker.json.jbuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.partial! "fertilizer_trackers/fertilizer_tracker", fertilizer_tracker: @fertilizer_tracker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |