-
Notifications
You must be signed in to change notification settings - Fork 6
Finish Lab #3
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?
Finish Lab #3
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,31 @@ | ||
class PizzasController < ApplicationController | ||
def new | ||
puts params | ||
if params[:pizzeria_id] | ||
@pizzeria = Pizzeria.find(params[:pizzeria_id]) | ||
@pizza = Pizza.new | ||
else | ||
@pizza = Pizza.new | ||
end | ||
end | ||
|
||
def create | ||
@pizza = Pizza.new(pizza_params) | ||
|
||
if @pizza.save | ||
redirect_to pizza_path @pizza, notice: 'Pizza was successfully created.' | ||
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. If you're not handling the |
||
else | ||
render :new | ||
end | ||
end | ||
|
||
def show | ||
@pizza = Pizza.find(params[:id]) | ||
end | ||
|
||
private | ||
|
||
def pizza_params | ||
params.require(:pizza).permit(:pizzeria_id, :name, :description) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,6 @@ | ||||||||||||||||
class Pizza < ApplicationRecord | ||||||||||||||||
belongs_to :pizzeria | ||||||||||||||||
validates :name, presence: true | ||||||||||||||||
validates :description, presence: true | ||||||||||||||||
validates :pizzeria_id, presence: true | ||||||||||||||||
Comment on lines
+2
to
+5
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 |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,3 +1,5 @@ | ||||||||||||||||
class Pizzeria < ApplicationRecord | ||||||||||||||||
|
||||||||||||||||
has_many :pizzas | ||||||||||||||||
validates :name, presence: true, uniqueness: true | ||||||||||||||||
validates :address, presence: true, uniqueness: true | ||||||||||||||||
Comment on lines
+2
to
+4
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<% 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 %> | ||
|
||
<%= form_with model: [@pizzeria, @pizza], local: true do |f| %> | ||
<%= f.label :name %> | ||
<%= f.text_field :name %> | ||
<% if @pizzeria.present? %> | ||
<%= f.hidden_field :pizzeria_id, value: @pizzeria.id %> | ||
<% end %> | ||
Comment on lines
+15
to
+17
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. The conditional wouldn't be needed if you set |
||
|
||
<%= f.label :description %> | ||
<%= f.text_field :description %> | ||
|
||
<%= f.submit %> | ||
<% end %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1><%= @pizza.name %> from <%= link_to @pizza.pizzeria.name, pizzeria_path(@pizza.pizzeria) %></h1> | ||
<p><%= @pizza.description %></p> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
<h1 style='margin-top:100px'>Pizzeria name: <%= @pizzeria.name %></h1> | ||
<p>Address: <%= @pizzeria.address %></p> | ||
<%= link_to "Tell us about a great pizza you had at #{@pizzeria.name}", new_pizzeria_pizza_path(@pizzeria.id) %> | ||
|
||
<h6>Pizzas:</h6> | ||
<ul> | ||
<% @pizzeria.pizzas.each do |pizza| %> | ||
<li> | ||
<h4><%= pizza.name %></h4> | ||
<p><%= pizza.description %></p> | ||
</li> | ||
<% end %> | ||
</ul> |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||
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 :pizzerias, only: [:new, :create, :show, :index] do | ||||
resources :pizzas, only: [:new, :create, :show] | ||||
end | ||||
|
||||
resources :pizzas, only: [:new, :create, :show] | ||||
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. Shouldn't need this line.
Suggested change
|
||||
end |
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 | ||
t.timestamps | ||
end | ||
end | ||
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. Don't commit files/changes that don't involve your changes. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
# This model initially had no columns defined. If you add columns to the | ||
# model remove the '{}' from the fixture names and add the columns immediately | ||
# below each fixture, per the syntax in the comments below | ||
# | ||
one: {} | ||
# column: value | ||
# | ||
two: {} | ||
# column: value |
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. Same here. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'test_helper' | ||
|
||
class PizzaTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |
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.
3 weeks of asking you to stop committing this!!!!! If I see this on the actual code challenge, I'm going to fail you immediately.