diff --git a/Gemfile b/Gemfile index 24a30f0..d487912 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index f6c82fe..22af6b1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -116,6 +117,7 @@ PLATFORMS DEPENDENCIES coffee-rails (~> 4.0.0) + hirb jbuilder (~> 1.2) jquery-rails pry diff --git a/app/models/ingredient.rb b/app/models/ingredient.rb new file mode 100644 index 0000000..70445cb --- /dev/null +++ b/app/models/ingredient.rb @@ -0,0 +1,4 @@ +class Ingredient < ActiveRecord::Base + has_many :recipes + has_many :menu_items, :through => :recipes +end diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index 8440100..37c3026 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -1,2 +1,4 @@ class MenuItem < ActiveRecord::Base + has_many :recipes + has_many :ingredients, :through => :recipes end diff --git a/app/models/recipe.rb b/app/models/recipe.rb new file mode 100644 index 0000000..8092aa1 --- /dev/null +++ b/app/models/recipe.rb @@ -0,0 +1,4 @@ +class Recipe < ActiveRecord::Base + belongs_to :menu_item + belongs_to :ingredient +end diff --git a/app/views/menu_items/index.html.erb b/app/views/menu_items/index.html.erb index b1db6a9..c451c1c 100644 --- a/app/views/menu_items/index.html.erb +++ b/app/views/menu_items/index.html.erb @@ -13,6 +13,7 @@ <% @menu_items.each do |menu_item| %>
<%= menu_item.name %>
<%= menu_item.price %>
<%= notice %>
+<%= @menu_item.name %>
+<%= @menu_item.price %>
+ <%= link_to 'Edit', edit_menu_item_path(@menu_item) %> | <%= link_to 'Back', menu_items_path %> diff --git a/config/routes.rb b/config/routes.rb index 8320abf..dd13419 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20131012205824_add_price_to_menu_items.rb b/db/migrate/20131012205824_add_price_to_menu_items.rb new file mode 100644 index 0000000..38d7853 --- /dev/null +++ b/db/migrate/20131012205824_add_price_to_menu_items.rb @@ -0,0 +1,5 @@ +class AddPriceToMenuItems < ActiveRecord::Migration + def change + add_column :menu_items, :price, :string + end +end diff --git a/db/migrate/20131012211224_create_ingredients.rb b/db/migrate/20131012211224_create_ingredients.rb new file mode 100644 index 0000000..b9ba5fb --- /dev/null +++ b/db/migrate/20131012211224_create_ingredients.rb @@ -0,0 +1,8 @@ +class CreateIngredients < ActiveRecord::Migration + def change + create_table :ingredients do |t| + t.string :food_thing + t.timestamps + end + end +end diff --git a/db/migrate/20131012212122_create_recipes.rb b/db/migrate/20131012212122_create_recipes.rb new file mode 100644 index 0000000..c843e35 --- /dev/null +++ b/db/migrate/20131012212122_create_recipes.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..e9eb532 --- /dev/null +++ b/db/schema.rb @@ -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 diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e8..cc46f86 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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) \ No newline at end of file diff --git a/test/fixtures/ingredients.yml b/test/fixtures/ingredients.yml new file mode 100644 index 0000000..c63aac0 --- /dev/null +++ b/test/fixtures/ingredients.yml @@ -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 diff --git a/test/fixtures/recipes.yml b/test/fixtures/recipes.yml new file mode 100644 index 0000000..7cf14a0 --- /dev/null +++ b/test/fixtures/recipes.yml @@ -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: diff --git a/test/models/ingredients_test.rb b/test/models/ingredients_test.rb new file mode 100644 index 0000000..441fe90 --- /dev/null +++ b/test/models/ingredients_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class IngredientsTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/recipe_test.rb b/test/models/recipe_test.rb new file mode 100644 index 0000000..5f53f19 --- /dev/null +++ b/test/models/recipe_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class RecipeTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end