-
Notifications
You must be signed in to change notification settings - Fork 27
completed panda, tiger, & eagle assignments #20
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,9 @@ | ||
class CreateRecipes < ActiveRecord::Migration | ||
def change | ||
create_table :recipes do |t| | ||
t.string :dish | ||
t.string :ingredients | ||
t.string :instructions | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Recipe < ActiveRecord::Base | ||
|
||
validates_presence_of :dish | ||
|
||
def to_s | ||
"#{dish} has the following ingredients #{ingredients} " | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,34 @@ | |
require "./db/seed" | ||
|
||
puts "There are #{Show.count} in the database" | ||
puts "What day of the week would you like to watch a show?" | ||
day_of_week = gets.chomp | ||
|
||
show_in_entered_day_of_week = false | ||
Network.all.each do |network| | ||
puts "Shows airing on #{network}" | ||
network.shows.each do |show| | ||
puts show | ||
end | ||
if show.day_of_week == day_of_week | ||
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. When you have a loop that inside has an if statement, I recommend the following: network.shows.to_a.select{|show| show.day_of_week == day_of_week} do |show|
puts show
end There's also the ability to do this in SQL: Show.where(day_of_week: day_of_week).each do |show|
end |
||
puts "#{show} on #{network}" | ||
show_in_entered_day_of_week = true | ||
end | ||
end | ||
end | ||
puts "no shows air on #{day_of_week}" unless show_in_entered_day_of_week | ||
puts "\n\n\n\n" | ||
|
||
|
||
puts "These are the all the dishes in the database :" | ||
Recipe.all.each do |recipe| | ||
puts "#{recipe}" | ||
end | ||
puts "What would you like to make?" | ||
dish = gets.chomp | ||
recipe_exists = false | ||
Recipe.all.each do |recipe| | ||
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. I like this, but I wouldn't recommend having the extra variable around (recipe_exists). Instead, maybe: recipes = Recipe.where(dish: dish)
recipes.each do |recipe|
puts recipe #and other stuff
end
puts "Sorry, #{dish} does not exist in the database" if recipes.blank? |
||
if recipe.dish == dish | ||
puts "This is how you make #{dish} :" | ||
puts "#{recipe.instructions}" | ||
recipe_exists = true | ||
end | ||
end | ||
puts "Sorry, #{dish} does not exist in the database" unless recipe_exists |
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.
yum!