diff --git a/Gemfile b/Gemfile
index 8bd546f..2fd0b17 100644
--- a/Gemfile
+++ b/Gemfile
@@ -31,6 +31,8 @@ gem 'jbuilder', '~> 2.5'
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
+gem 'bourbon'
+
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
diff --git a/Gemfile.lock b/Gemfile.lock
index c017465..8f55208 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -42,6 +42,8 @@ GEM
base64 (0.2.0)
bcrypt (3.1.20)
bindex (0.8.1)
+ bourbon (7.3.0)
+ thor (~> 1.0)
builder (3.3.0)
byebug (11.1.3)
coffee-rails (4.2.2)
@@ -186,6 +188,7 @@ PLATFORMS
DEPENDENCIES
bcrypt (~> 3.1.7)
+ bourbon
byebug
coffee-rails (~> 4.2)
jbuilder (~> 2.5)
diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss
index ef4d632..0dabad4 100644
--- a/app/assets/stylesheets/application.scss
+++ b/app/assets/stylesheets/application.scss
@@ -14,20 +14,24 @@
@import "base/base";
.container {
- width:1000px;
- margin:auto;
- margin-top:50px;
+ width: 1000px;
+ margin: auto;
+ margin-top: 50px;
}
.form-container {
- width:500px;
+ width: 500px;
}
.pizza_logo {
width: 100px;
-webkit-animation: spin 5s infinite linear;
@-webkit-keyframes spin {
- 0% {-webkit-transform: rotate(0deg)}
- 100% {-webkit-transform: rotate(360deg)}
+ 0% {
+ -webkit-transform: rotate(0deg);
+ }
+ 100% {
+ -webkit-transform: rotate(360deg);
+ }
}
}
diff --git a/app/controllers/pizzas_controller.rb b/app/controllers/pizzas_controller.rb
new file mode 100644
index 0000000..011b49d
--- /dev/null
+++ b/app/controllers/pizzas_controller.rb
@@ -0,0 +1,29 @@
+class PizzasController < ApplicationController
+ def new
+ @pizzeria = Pizzeria.find(params[:pizzeria_id])
+ @pizza = Pizza.new
+ end
+
+ def create
+ @pizzeria = Pizzeria.find(params[:pizzeria_id])
+ @pizza = @pizzeria.pizzas.build(pizza_params)
+
+ if @pizza.save
+ redirect_to @pizzeria
+ render :new
+ end
+ end
+
+ def show
+ @pizza = Pizza.find(params[:id])
+ end
+
+ def index
+ @pizzas = Pizza.all
+ end
+
+ private
+ def pizza_params
+ params.require(:pizza).permit(:name,:description)
+ end
+end
diff --git a/app/models/pizza.rb b/app/models/pizza.rb
new file mode 100644
index 0000000..1aab51e
--- /dev/null
+++ b/app/models/pizza.rb
@@ -0,0 +1,5 @@
+class Pizza < ApplicationRecord
+ belongs_to :pizzeria
+
+ validates :name, :description, presence: true
+end
diff --git a/app/models/pizzeria.rb b/app/models/pizzeria.rb
index cbedbf7..142d1c3 100644
--- a/app/models/pizzeria.rb
+++ b/app/models/pizzeria.rb
@@ -1,3 +1,5 @@
class Pizzeria < ApplicationRecord
-
+ has_many :pizzas
+
+ validates :name, :address, presence:true
end
diff --git a/app/views/pizzas/new.html.erb b/app/views/pizzas/new.html.erb
new file mode 100644
index 0000000..e7f0c16
--- /dev/null
+++ b/app/views/pizzas/new.html.erb
@@ -0,0 +1,26 @@
+
Add a New Pizza to <%= @pizzeria.name %>
+
+<%= form_with model: [@pizzeria, @pizza], local: true do |f| %>
+
+ <% if @pizza.errors.any? %>
+
+
<%= pluralize(@pizza.errors.count, "error") %> prohibited this pizza from being saved:
+
+ <% @pizza.errors.full_messages.each do |message| %>
+ - <%= message %>
+ <% end %>
+
+
+ <% end %>
+
+ <%= f.label :name %>
+ <%= f.text_field :name %>
+
+
+ <%= f.label :description %>
+ <%= f.text_area :description %>
+
+
+ <%= f.submit 'Create Pizza' %>
+
+<% end %>
diff --git a/app/views/pizzas/show.html.erb b/app/views/pizzas/show.html.erb
new file mode 100644
index 0000000..ba8f31b
--- /dev/null
+++ b/app/views/pizzas/show.html.erb
@@ -0,0 +1,4 @@
+<%="#{@pizza.name} from "%>
+<%=link_to @pizza.pizzeria.name, pizzeria_path(@pizza.pizzeria)%>
+
+Description: <%=@pizza.description%>
diff --git a/app/views/pizzerias/show.html.erb b/app/views/pizzerias/show.html.erb
index 32bcfef..94aa5db 100644
--- a/app/views/pizzerias/show.html.erb
+++ b/app/views/pizzerias/show.html.erb
@@ -1,2 +1,11 @@
Pizzeria name: <%= @pizzeria.name %>
Address: <%= @pizzeria.address %>
+
+<%= link_to "Tell us about a great pizza you had at #{@pizzeria.name}", new_pizzeria_pizza_path(@pizzeria)%>
+
+Great eats from <%= @pizzeria.name %>
+
+ <% @pizzeria.pizzas.each do |pizza| %>
+ - <%=link_to pizza.name, pizza_path(pizza) %>
+ <% end %>
+
diff --git a/config/routes.rb b/config/routes.rb
index a267746..2914c25 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,6 +1,8 @@
Rails.application.routes.draw do
- get '/pizzerias/new', to: 'pizzerias#new', as: 'new_pizzeria'
- post '/pizzerias', to: 'pizzerias#create', as: 'pizzerias'
- get '/pizzerias/:id', to: 'pizzerias#show', as: 'pizzeria'
- get '/pizzerias', to: 'pizzerias#index'
+ resources :pizzas, only: [:new, :create, :show]
+ resources :pizzerias
+
+ resources :pizzerias do
+ resources :pizzas, only: [:new, :create, :show]
+ end
end
diff --git a/db/migrate/20170808134858_create_locations.rb b/db/migrate/20170808134858_create_locations.rb
deleted file mode 100644
index eb8e8a6..0000000
--- a/db/migrate/20170808134858_create_locations.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-class CreateLocations < ActiveRecord::Migration[5.1]
- def change
- create_table :locations do |t|
- t.string :name
- t.string :address
- end
- end
-end
diff --git a/db/migrate/20170808134858_create_pizzerias.rb b/db/migrate/20170808134858_create_pizzerias.rb
new file mode 100644
index 0000000..5b4b2f5
--- /dev/null
+++ b/db/migrate/20170808134858_create_pizzerias.rb
@@ -0,0 +1,8 @@
+class CreatePizzerias < ActiveRecord::Migration[5.1]
+ def change
+ create_table :pizzerias do |t|
+ t.string :name
+ t.string :address
+ end
+ end
+end
diff --git a/db/migrate/20170814143728_rename_locaitons_to_pizzerias.rb b/db/migrate/20170814143728_rename_locaitons_to_pizzerias.rb
deleted file mode 100644
index 9c7e6cf..0000000
--- a/db/migrate/20170814143728_rename_locaitons_to_pizzerias.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-class RenameLocaitonsToPizzerias < ActiveRecord::Migration[5.1]
- def change
- rename_table :locations, :pizzerias
- end
-end
diff --git a/db/migrate/20240821125409_create_pizzas.rb b/db/migrate/20240821125409_create_pizzas.rb
new file mode 100644
index 0000000..c16d27f
--- /dev/null
+++ b/db/migrate/20240821125409_create_pizzas.rb
@@ -0,0 +1,10 @@
+class CreatePizzas < ActiveRecord::Migration[5.1]
+ def change
+ create_table :pizzas do |t|
+ t.string :name
+ t.string :description
+
+ t.references :pizzeria, foreign_key: true
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 20bcce4..aeb58b6 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,14 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20170814143728) do
+ActiveRecord::Schema.define(version: 20240821125409) do
+
+ create_table "pizzas", force: :cascade do |t|
+ t.string "name"
+ t.string "description"
+ t.integer "pizzeria_id"
+ t.index ["pizzeria_id"], name: "index_pizzas_on_pizzeria_id"
+ end
create_table "pizzerias", force: :cascade do |t|
t.string "name"
diff --git a/db/seeds.rb b/db/seeds.rb
index eb0ee15..de9d4ef 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -1,23 +1,33 @@
-# This file should contain all the record creation needed to seed the database with its default values.
-# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
-#
-# Examples:
-#
-# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
-# Character.create(name: 'Luke', movie: movies.first)
-#
-# 1
+# Clear existing data
Pizzeria.destroy_all
-
-Pizzeria.create!([{
- name: "Sottocasa NYC",
- address: "298 Atlantic Ave, Brooklyn, NY 11201",
-},
-{
- name: "PizzArte",
- address: "69 W 55th St, New York, NY 10019",
-},
-{
- name: "San Matteo NYC",
- address: "1559 2nd Ave, New York, NY 10028"
-}])
+Pizza.destroy_all
+
+# Create pizzerias
+pizzerias = Pizzeria.create!([
+ {
+ name: "Sottocasa NYC",
+ address: "298 Atlantic Ave, Brooklyn, NY 11201",
+ },
+ {
+ name: "PizzArte",
+ address: "69 W 55th St, New York, NY 10019",
+ },
+ {
+ name: "San Matteo NYC",
+ address: "1559 2nd Ave, New York, NY 10028"
+ }
+])
+
+# Create pizzas and associate them with pizzerias
+pizzas = [
+ { name: "Margherita", description: "Classic pizza with tomato, mozzarella, and basil", pizzeria: pizzerias[0] },
+ { name: "Pepperoni", description: "Pepperoni, mozzarella, and tomato sauce", pizzeria: pizzerias[0] },
+ { name: "Quattro Formaggi", description: "Four cheese pizza with mozzarella, gorgonzola, fontina, and parmesan", pizzeria: pizzerias[1] },
+ { name: "Diavola", description: "Spicy pizza with pepperoni, chili peppers, and mozzarella", pizzeria: pizzerias[1] },
+ { name: "Marinara", description: "Tomato, garlic, oregano, and extra virgin olive oil", pizzeria: pizzerias[2] },
+ { name: "Prosciutto e Funghi", description: "Ham, mushrooms, mozzarella, and tomato sauce", pizzeria: pizzerias[2] }
+]
+
+Pizza.create!(pizzas)
+
+puts "Seeding completed!"