Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ group :doc do
gem 'sdoc', require: false
end

gem 'hirb'

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ GEM
erubis (2.7.0)
execjs (2.0.2)
hike (1.2.3)
hirb (0.7.1)
i18n (0.6.5)
jbuilder (1.5.2)
activesupport (>= 3.0.0)
Expand Down Expand Up @@ -116,6 +117,7 @@ PLATFORMS

DEPENDENCIES
coffee-rails (~> 4.0.0)
hirb
jbuilder (~> 1.2)
jquery-rails
pry
Expand Down
4 changes: 4 additions & 0 deletions app/models/ingredient.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Ingredient < ActiveRecord::Base
has_many :recipes
has_many :menu_items, :through => :recipes
end
2 changes: 2 additions & 0 deletions app/models/menu_item.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
class MenuItem < ActiveRecord::Base
has_many :recipes
has_many :ingredients, :through => :recipes
end
4 changes: 4 additions & 0 deletions app/models/recipe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Recipe < ActiveRecord::Base
belongs_to :menu_item
belongs_to :ingredient
end
1 change: 1 addition & 0 deletions app/views/menu_items/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<% @menu_items.each do |menu_item| %>
<tr>
<td><p><%= menu_item.name %></p></td>
<td><p><%= menu_item.price %></p></td>
<td><%= link_to 'Show', menu_item %></td>
<td><%= link_to 'Edit', edit_menu_item_path(menu_item) %></td>
<td><%= link_to 'Destroy', menu_item, method: :delete, data: { confirm: 'Are you sure?' } %></td>
Expand Down
3 changes: 3 additions & 0 deletions app/views/menu_items/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<p id="notice"><%= notice %></p>

<p><%= @menu_item.name %></p>
<p><%= @menu_item.price %></p>

<%= link_to 'Edit', edit_menu_item_path(@menu_item) %> |
<%= link_to 'Back', menu_items_path %>
54 changes: 1 addition & 53 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,56 +1,4 @@
Makerbistro::Application.routes.draw do
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

# You can have the root of your site routed with "root"
# root 'welcome#index'

# Example of regular route:
# get 'products/:id' => 'catalog#view'

# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase

# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products

# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end

# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end

# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end
resources :menu_items

# Example resource route with concerns:
# concern :toggleable do
# post 'toggle'
# end
# resources :posts, concerns: :toggleable
# resources :photos, concerns: :toggleable

# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
end
5 changes: 5 additions & 0 deletions db/migrate/20131012205824_add_price_to_menu_items.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPriceToMenuItems < ActiveRecord::Migration
def change
add_column :menu_items, :price, :string
end
end
8 changes: 8 additions & 0 deletions db/migrate/20131012211224_create_ingredients.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CreateIngredients < ActiveRecord::Migration
def change
create_table :ingredients do |t|
t.string :food_thing
t.timestamps
end
end
end
10 changes: 10 additions & 0 deletions db/migrate/20131012212122_create_recipes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateRecipes < ActiveRecord::Migration
def change
create_table :recipes do |t|
t.references :menu_item, index: true
t.references :ingredient, index: true

t.timestamps
end
end
end
39 changes: 39 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20131012212122) do

create_table "ingredients", force: true do |t|
t.string "food_thing"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "menu_items", force: true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.string "price"
end

create_table "recipes", force: true do |t|
t.integer "menu_item_id"
t.integer "ingredient_id"
t.datetime "created_at"
t.datetime "updated_at"
end

add_index "recipes", ["ingredient_id"], name: "index_recipes_on_ingredient_id"
add_index "recipes", ["menu_item_id"], name: "index_recipes_on_menu_item_id"

end
20 changes: 20 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,23 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)

pasta = MenuItem.create(name: "pasta", price: "$10")

# .ingredients.create([food_thing: "noodles", food_thing: "sauce", food_thing: "garlic"])
cheesebread = MenuItem.create(name: "cheesey bread", price: "$5")
pizza = MenuItem.create(name: "pizza", price: "$15")

dough = Ingredient.create(food_thing: "dough")
sauce = Ingredient.create(food_thing: "sauce")
cheese = Ingredient.create(food_thing: "cheese")
noodles = Ingredient.create(food_thing: "noodles")
meat = Ingredient.create(food_thing: "meat")
garlic = Ingredient.create(food_thing: "garlic")

spaghetti = pasta.recipes.create(ingredient: noodles)
spaghetti = pasta.recipes.create(ingredient: sauce)
spaghetti = pasta.recipes.create(ingredient: garlic)
# testfood = MenuItem.first.recipes.create
# testfood2 = MenuItem.last.recipes.create ingredient_id: 1
# pasta.recipes.create(ingredient: noodles)
11 changes: 11 additions & 0 deletions test/fixtures/ingredients.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.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
9 changes: 9 additions & 0 deletions test/fixtures/recipes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html

one:
menu_item_id:
ingredient_id:

two:
menu_item_id:
ingredient_id:
7 changes: 7 additions & 0 deletions test/models/ingredients_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class IngredientsTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/recipe_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class RecipeTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end