-
Notifications
You must be signed in to change notification settings - Fork 6
Create and display pizzas #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Pizza < ApplicationRecord | ||
belongs_to :pizzeria | ||
|
||
validates :name, :description, presence: true | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
class Pizzeria < ApplicationRecord | ||
|
||
has_many :pizzas | ||
|
||
validates :name, :address, presence:true | ||
end |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code looks good, spacing could use some work. Adding a line between |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<h1>Add a New Pizza to <%= @pizzeria.name %></h1> | ||
|
||
<%= form_with model: [@pizzeria, @pizza], local: true do |f| %> | ||
|
||
<% if @pizza.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@pizza.errors.count, "error") %> prohibited this pizza from being saved:</h2> | ||
<ul> | ||
<% @pizza.errors.full_messages.each do |message| %> | ||
<li><%= message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
<div> | ||
<%= f.label :name %> | ||
<%= f.text_field :name %> | ||
</div> | ||
<div> | ||
<%= f.label :description %> | ||
<%= f.text_area :description %> | ||
</div> | ||
<div> | ||
<%= f.submit 'Create Pizza' %> | ||
</div> | ||
<% end %> |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,4 @@ | ||||||
<h1><%="#{@pizza.name} from "%> | ||||||
<%=link_to @pizza.pizzeria.name, pizzeria_path(@pizza.pizzeria)%> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
</h1> | ||||||
<p>Description: <%[email protected]%> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,2 +1,11 @@ | ||||||
<h1 style='margin-top:100px'>Pizzeria name: <%= @pizzeria.name %></h1> | ||||||
<p>Address: <%= @pizzeria.address %></p> | ||||||
|
||||||
<p><%= link_to "Tell us about a great pizza you had at #{@pizzeria.name}", new_pizzeria_pizza_path(@pizzeria)%></p> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
<h2>Great eats from <%= @pizzeria.name %></h2> | ||||||
<ol> | ||||||
<% @pizzeria.pizzas.each do |pizza| %> | ||||||
<li><%=link_to pizza.name, pizza_path(pizza) %></li> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<% end %> | ||||||
</ol> |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -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 | ||||||||||||||||||
Comment on lines
+3
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops!
Suggested change
|
||||||||||||||||||
end |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldn't be deleting migrations. Assume that the migrations that were given to you are already "in production" and can't be undone. |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't commit changes like this for the actual code challenge. Pay attention to what you're committing EVERY TIME.