From 1c1cf5ba58703a188255f6be664f60d6c57c9b42 Mon Sep 17 00:00:00 2001 From: Alex Levine Date: Thu, 10 Oct 2013 16:24:35 -0500 Subject: [PATCH 1/9] ready for students to use --- app/assets/javascripts/ingredients.js.coffee | 3 -- app/assets/stylesheets/ingredients.css.scss | 3 -- app/controllers/ingredients_controller.rb | 19 ------- app/helpers/ingredients_helper.rb | 2 - app/models/ingredient.rb | 4 -- app/models/menu_item.rb | 2 - app/models/recipe.rb | 4 -- config/routes.rb | 4 -- .../20131010155724_create_menu_items.rb | 2 - db/migrate/20131010155836_create_recipes.rb | 9 ---- .../20131010155915_create_ingredients.rb | 9 ---- db/schema.rb | 36 -------------- test/controllers/.keep | 0 .../ingredients_controller_test.rb | 7 --- .../controllers/menu_items_controller_test.rb | 49 ------------------- test/fixtures/.keep | 0 test/fixtures/ingredients.yml | 7 --- test/fixtures/menu_items.yml | 9 ---- test/fixtures/recipes.yml | 11 ----- test/helpers/.keep | 0 test/helpers/ingredients_helper_test.rb | 4 -- test/helpers/menu_items_helper_test.rb | 4 -- test/integration/.keep | 0 test/mailers/.keep | 0 test/models/.keep | 0 test/models/ingredient_test.rb | 7 --- test/models/menu_item_test.rb | 7 --- test/models/recipe_test.rb | 7 --- test/test_helper.rb | 15 ------ 29 files changed, 224 deletions(-) delete mode 100644 app/assets/javascripts/ingredients.js.coffee delete mode 100644 app/assets/stylesheets/ingredients.css.scss delete mode 100644 app/controllers/ingredients_controller.rb delete mode 100644 app/helpers/ingredients_helper.rb delete mode 100644 app/models/ingredient.rb delete mode 100644 app/models/recipe.rb delete mode 100644 db/migrate/20131010155836_create_recipes.rb delete mode 100644 db/migrate/20131010155915_create_ingredients.rb delete mode 100644 db/schema.rb delete mode 100644 test/controllers/.keep delete mode 100644 test/controllers/ingredients_controller_test.rb delete mode 100644 test/controllers/menu_items_controller_test.rb delete mode 100644 test/fixtures/.keep delete mode 100644 test/fixtures/ingredients.yml delete mode 100644 test/fixtures/menu_items.yml delete mode 100644 test/fixtures/recipes.yml delete mode 100644 test/helpers/.keep delete mode 100644 test/helpers/ingredients_helper_test.rb delete mode 100644 test/helpers/menu_items_helper_test.rb delete mode 100644 test/integration/.keep delete mode 100644 test/mailers/.keep delete mode 100644 test/models/.keep delete mode 100644 test/models/ingredient_test.rb delete mode 100644 test/models/menu_item_test.rb delete mode 100644 test/models/recipe_test.rb delete mode 100644 test/test_helper.rb diff --git a/app/assets/javascripts/ingredients.js.coffee b/app/assets/javascripts/ingredients.js.coffee deleted file mode 100644 index 24f83d1..0000000 --- a/app/assets/javascripts/ingredients.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/ingredients.css.scss b/app/assets/stylesheets/ingredients.css.scss deleted file mode 100644 index 1953e14..0000000 --- a/app/assets/stylesheets/ingredients.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the Ingredients controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/ingredients_controller.rb b/app/controllers/ingredients_controller.rb deleted file mode 100644 index 88e2941..0000000 --- a/app/controllers/ingredients_controller.rb +++ /dev/null @@ -1,19 +0,0 @@ -class IngredientsController < ApplicationController - def create - # @menu_item = - # @ingredient = - - end - - private - # Use callbacks to share common setup or constraints between actions. - # def set_menu_item - # @menu_item = MenuItem.find(params[:id]) - # end - - # # Never trust parameters from the scary internet, only allow the white list through. - # def menu_item_params - # params.require(:menu_item).permit(:name) - # end - -end diff --git a/app/helpers/ingredients_helper.rb b/app/helpers/ingredients_helper.rb deleted file mode 100644 index dd54783..0000000 --- a/app/helpers/ingredients_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module IngredientsHelper -end diff --git a/app/models/ingredient.rb b/app/models/ingredient.rb deleted file mode 100644 index f8367ed..0000000 --- a/app/models/ingredient.rb +++ /dev/null @@ -1,4 +0,0 @@ -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 6ba37a8..8440100 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -1,4 +1,2 @@ class MenuItem < ActiveRecord::Base - has_one :recipe - has_many :ingredients, through: :recipe end diff --git a/app/models/recipe.rb b/app/models/recipe.rb deleted file mode 100644 index 5f5d28d..0000000 --- a/app/models/recipe.rb +++ /dev/null @@ -1,4 +0,0 @@ -class Recipe < ActiveRecord::Base - belongs_to :menu_item - belongs_to :ingredient -end diff --git a/config/routes.rb b/config/routes.rb index f26336e..8320abf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,10 +5,6 @@ # You can have the root of your site routed with "root" # root 'welcome#index' - resources :menu_items do - resources :ingredients, only: [:create] - end - # Example of regular route: # get 'products/:id' => 'catalog#view' diff --git a/db/migrate/20131010155724_create_menu_items.rb b/db/migrate/20131010155724_create_menu_items.rb index ae058ad..8278a6c 100644 --- a/db/migrate/20131010155724_create_menu_items.rb +++ b/db/migrate/20131010155724_create_menu_items.rb @@ -2,8 +2,6 @@ class CreateMenuItems < ActiveRecord::Migration def change create_table :menu_items do |t| t.string :name - t.string :price - t.timestamps end end diff --git a/db/migrate/20131010155836_create_recipes.rb b/db/migrate/20131010155836_create_recipes.rb deleted file mode 100644 index e2ae30c..0000000 --- a/db/migrate/20131010155836_create_recipes.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateRecipes < ActiveRecord::Migration - def change - create_table :recipes do |t| - t.references :menu_item - t.references :ingredient - t.timestamps - end - end -end diff --git a/db/migrate/20131010155915_create_ingredients.rb b/db/migrate/20131010155915_create_ingredients.rb deleted file mode 100644 index 21723bf..0000000 --- a/db/migrate/20131010155915_create_ingredients.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateIngredients < ActiveRecord::Migration - def change - create_table :ingredients do |t| - t.string :name - - t.timestamps - end - end -end diff --git a/db/schema.rb b/db/schema.rb deleted file mode 100644 index bb072f1..0000000 --- a/db/schema.rb +++ /dev/null @@ -1,36 +0,0 @@ -# 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: 20131010155915) do - - create_table "ingredients", force: true do |t| - t.string "name" - t.datetime "created_at" - t.datetime "updated_at" - end - - create_table "menu_items", force: true do |t| - t.string "name" - t.string "price" - t.datetime "created_at" - t.datetime "updated_at" - 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 - -end diff --git a/test/controllers/.keep b/test/controllers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/controllers/ingredients_controller_test.rb b/test/controllers/ingredients_controller_test.rb deleted file mode 100644 index 8bce723..0000000 --- a/test/controllers/ingredients_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class IngredientsControllerTest < ActionController::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/controllers/menu_items_controller_test.rb b/test/controllers/menu_items_controller_test.rb deleted file mode 100644 index 4aa8ef9..0000000 --- a/test/controllers/menu_items_controller_test.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'test_helper' - -class MenuItemsControllerTest < ActionController::TestCase - setup do - @menu_item = menu_items(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:menu_items) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create menu_item" do - assert_difference('MenuItem.count') do - post :create, menu_item: { } - end - - assert_redirected_to menu_item_path(assigns(:menu_item)) - end - - test "should show menu_item" do - get :show, id: @menu_item - assert_response :success - end - - test "should get edit" do - get :edit, id: @menu_item - assert_response :success - end - - test "should update menu_item" do - patch :update, id: @menu_item, menu_item: { } - assert_redirected_to menu_item_path(assigns(:menu_item)) - end - - test "should destroy menu_item" do - assert_difference('MenuItem.count', -1) do - delete :destroy, id: @menu_item - end - - assert_redirected_to menu_items_path - end -end diff --git a/test/fixtures/.keep b/test/fixtures/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/fixtures/ingredients.yml b/test/fixtures/ingredients.yml deleted file mode 100644 index 0227c60..0000000 --- a/test/fixtures/ingredients.yml +++ /dev/null @@ -1,7 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - -one: - name: MyString - -two: - name: MyString diff --git a/test/fixtures/menu_items.yml b/test/fixtures/menu_items.yml deleted file mode 100644 index 2c8154b..0000000 --- a/test/fixtures/menu_items.yml +++ /dev/null @@ -1,9 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - -one: - name: MyString - price: MyString - -two: - name: MyString - price: MyString diff --git a/test/fixtures/recipes.yml b/test/fixtures/recipes.yml deleted file mode 100644 index c63aac0..0000000 --- a/test/fixtures/recipes.yml +++ /dev/null @@ -1,11 +0,0 @@ -# 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/helpers/.keep b/test/helpers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/helpers/ingredients_helper_test.rb b/test/helpers/ingredients_helper_test.rb deleted file mode 100644 index fc19ac4..0000000 --- a/test/helpers/ingredients_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class IngredientsHelperTest < ActionView::TestCase -end diff --git a/test/helpers/menu_items_helper_test.rb b/test/helpers/menu_items_helper_test.rb deleted file mode 100644 index 8919dfd..0000000 --- a/test/helpers/menu_items_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class MenuItemsHelperTest < ActionView::TestCase -end diff --git a/test/integration/.keep b/test/integration/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/mailers/.keep b/test/mailers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/models/.keep b/test/models/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/models/ingredient_test.rb b/test/models/ingredient_test.rb deleted file mode 100644 index 511fcf8..0000000 --- a/test/models/ingredient_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class IngredientTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/models/menu_item_test.rb b/test/models/menu_item_test.rb deleted file mode 100644 index 73f476d..0000000 --- a/test/models/menu_item_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class MenuItemTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/models/recipe_test.rb b/test/models/recipe_test.rb deleted file mode 100644 index 5f53f19..0000000 --- a/test/models/recipe_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class RecipeTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/test_helper.rb b/test/test_helper.rb deleted file mode 100644 index bc7e05d..0000000 --- a/test/test_helper.rb +++ /dev/null @@ -1,15 +0,0 @@ -ENV["RAILS_ENV"] ||= "test" -require File.expand_path('../../config/environment', __FILE__) -require 'rails/test_help' - -class ActiveSupport::TestCase - ActiveRecord::Migration.check_pending! - - # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. - # - # Note: You'll currently still have to declare fixtures explicitly in integration tests - # -- they do not yet inherit this setting - fixtures :all - - # Add more helper methods to be used by all tests here... -end From 951a2db3b5470d8234409b44c40cd5388de2bb62 Mon Sep 17 00:00:00 2001 From: bangner Date: Sun, 13 Oct 2013 22:46:57 -0500 Subject: [PATCH 2/9] first commit --- Gemfile | 4 ++++ Gemfile.lock | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/Gemfile b/Gemfile index 24a30f0..cdf3cd0 100644 --- a/Gemfile +++ b/Gemfile @@ -34,6 +34,10 @@ group :doc do gem 'sdoc', require: false end +gem 'haml' + +gem 'hirb' + # Use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index f6c82fe..30b7ae0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -38,7 +38,10 @@ GEM coffee-script-source (1.6.3) erubis (2.7.0) execjs (2.0.2) + haml (4.0.3) + tilt hike (1.2.3) + hirb (0.7.1) i18n (0.6.5) jbuilder (1.5.2) activesupport (>= 3.0.0) @@ -116,6 +119,8 @@ PLATFORMS DEPENDENCIES coffee-rails (~> 4.0.0) + haml + hirb jbuilder (~> 1.2) jquery-rails pry From 1f9d18fe9c9511b1b3317d35e63219c77e3ed6a4 Mon Sep 17 00:00:00 2001 From: bangner Date: Sun, 13 Oct 2013 23:08:17 -0500 Subject: [PATCH 3/9] add price to menu_items --- .../20131014040737_add_price_to_menu_items.rb | 5 ++++ db/schema.rb | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 db/migrate/20131014040737_add_price_to_menu_items.rb create mode 100644 db/schema.rb diff --git a/db/migrate/20131014040737_add_price_to_menu_items.rb b/db/migrate/20131014040737_add_price_to_menu_items.rb new file mode 100644 index 0000000..38d7853 --- /dev/null +++ b/db/migrate/20131014040737_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/schema.rb b/db/schema.rb new file mode 100644 index 0000000..0295d7e --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,23 @@ +# 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: 20131014040737) do + + create_table "menu_items", force: true do |t| + t.string "name" + t.datetime "created_at" + t.datetime "updated_at" + t.string "price" + end + +end From 7d247bd19d1b9bc8667a1642e56689ba4b00021b Mon Sep 17 00:00:00 2001 From: bangner Date: Sun, 13 Oct 2013 23:25:00 -0500 Subject: [PATCH 4/9] generated models for recipe and ingredient --- app/models/ingredient.rb | 2 ++ app/models/recipe.rb | 2 ++ .../20131014041455_add_price_to_menu_items.rb | 5 +++++ db/migrate/20131014042052_create_recipes.rb | 10 ++++++++++ .../20131014042123_create_ingredients.rb | 9 +++++++++ db/schema.rb | 18 +++++++++++++++++- test/fixtures/ingredients.yml | 11 +++++++++++ test/fixtures/recipes.yml | 11 +++++++++++ test/models/ingredient_test.rb | 7 +++++++ test/models/recipe_test.rb | 7 +++++++ 10 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 app/models/ingredient.rb create mode 100644 app/models/recipe.rb create mode 100644 db/migrate/20131014041455_add_price_to_menu_items.rb create mode 100644 db/migrate/20131014042052_create_recipes.rb create mode 100644 db/migrate/20131014042123_create_ingredients.rb create mode 100644 test/fixtures/ingredients.yml create mode 100644 test/fixtures/recipes.yml create mode 100644 test/models/ingredient_test.rb create mode 100644 test/models/recipe_test.rb diff --git a/app/models/ingredient.rb b/app/models/ingredient.rb new file mode 100644 index 0000000..700e9ec --- /dev/null +++ b/app/models/ingredient.rb @@ -0,0 +1,2 @@ +class Ingredient < ActiveRecord::Base +end diff --git a/app/models/recipe.rb b/app/models/recipe.rb new file mode 100644 index 0000000..0fba70f --- /dev/null +++ b/app/models/recipe.rb @@ -0,0 +1,2 @@ +class Recipe < ActiveRecord::Base +end diff --git a/db/migrate/20131014041455_add_price_to_menu_items.rb b/db/migrate/20131014041455_add_price_to_menu_items.rb new file mode 100644 index 0000000..38d7853 --- /dev/null +++ b/db/migrate/20131014041455_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/20131014042052_create_recipes.rb b/db/migrate/20131014042052_create_recipes.rb new file mode 100644 index 0000000..c843e35 --- /dev/null +++ b/db/migrate/20131014042052_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/migrate/20131014042123_create_ingredients.rb b/db/migrate/20131014042123_create_ingredients.rb new file mode 100644 index 0000000..1c22faf --- /dev/null +++ b/db/migrate/20131014042123_create_ingredients.rb @@ -0,0 +1,9 @@ +class CreateIngredients < ActiveRecord::Migration + def change + create_table :ingredients do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 0295d7e..89866d7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,13 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20131014040737) do +ActiveRecord::Schema.define(version: 20131014042123) do + + create_table "ingredients", force: true do |t| + t.string "name" + t.datetime "created_at" + t.datetime "updated_at" + end create_table "menu_items", force: true do |t| t.string "name" @@ -20,4 +26,14 @@ 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/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..c63aac0 --- /dev/null +++ b/test/fixtures/recipes.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/models/ingredient_test.rb b/test/models/ingredient_test.rb new file mode 100644 index 0000000..511fcf8 --- /dev/null +++ b/test/models/ingredient_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class IngredientTest < 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 From 982f028b880de72133444832e12afef3f742ff8b Mon Sep 17 00:00:00 2001 From: bangner Date: Sun, 13 Oct 2013 23:43:14 -0500 Subject: [PATCH 5/9] add root route and resources --- app/controllers/menu_items_controller.rb | 1 + app/models/ingredient.rb | 2 + app/models/menu_item.rb | 5 ++ app/models/recipe.rb | 2 + config/routes.rb | 57 ++----------------- .../20131014040737_add_price_to_menu_items.rb | 5 -- 6 files changed, 16 insertions(+), 56 deletions(-) delete mode 100644 db/migrate/20131014040737_add_price_to_menu_items.rb diff --git a/app/controllers/menu_items_controller.rb b/app/controllers/menu_items_controller.rb index b124cb4..449b3ba 100644 --- a/app/controllers/menu_items_controller.rb +++ b/app/controllers/menu_items_controller.rb @@ -10,6 +10,7 @@ def index # GET /menu_items/1 # GET /menu_items/1.json def show + @ingredients = @menu_item.ingredients end # GET /menu_items/new diff --git a/app/models/ingredient.rb b/app/models/ingredient.rb index 700e9ec..33174dc 100644 --- a/app/models/ingredient.rb +++ b/app/models/ingredient.rb @@ -1,2 +1,4 @@ class Ingredient < ActiveRecord::Base + has_many :recipes + has_many :menu_items, :through => :recipe end diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index 8440100..5f772b2 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -1,2 +1,7 @@ class MenuItem < ActiveRecord::Base + has_one :recipe + has_many :ingredients, :through => :recipe + + validates :name, presence: true + validates :price, presence: true end diff --git a/app/models/recipe.rb b/app/models/recipe.rb index 0fba70f..8092aa1 100644 --- a/app/models/recipe.rb +++ b/app/models/recipe.rb @@ -1,2 +1,4 @@ class Recipe < ActiveRecord::Base + belongs_to :menu_item + belongs_to :ingredient end diff --git a/config/routes.rb b/config/routes.rb index 8320abf..2561082 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,56 +1,11 @@ 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 + + root 'menu_items#index' - # Example resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end + resources :menu_items do + recources :ingredients + end - # Example resource route with more complex sub-resources: - # resources :products do - # resources :comments - # resources :sales do - # get 'recent', on: :collection - # end - # end - - # Example resource route with concerns: - # concern :toggleable do - # post 'toggle' - # end - # resources :posts, concerns: :toggleable - # resources :photos, concerns: :toggleable + resources :ingredients - # 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/20131014040737_add_price_to_menu_items.rb b/db/migrate/20131014040737_add_price_to_menu_items.rb deleted file mode 100644 index 38d7853..0000000 --- a/db/migrate/20131014040737_add_price_to_menu_items.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddPriceToMenuItems < ActiveRecord::Migration - def change - add_column :menu_items, :price, :string - end -end From 010d0e045ce1710897a080ff0b092eafa710f9d2 Mon Sep 17 00:00:00 2001 From: bangner Date: Mon, 14 Oct 2013 00:12:10 -0500 Subject: [PATCH 6/9] change index and show page --- app/assets/javascripts/ingredients.js.coffee | 3 +++ app/assets/stylesheets/ingredients.css.scss | 3 +++ app/controllers/ingredients_controller.rb | 25 +++++++++++++++++++ app/helpers/ingredients_helper.rb | 2 ++ app/models/menu_item.rb | 2 ++ app/views/menu_items/_form.html.erb | 1 + app/views/menu_items/index.html.erb | 5 +++- app/views/menu_items/show.html.erb | 8 ++++++ config/routes.rb | 7 +----- .../ingredients_controller_test.rb | 7 ++++++ test/helpers/ingredients_helper_test.rb | 4 +++ 11 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 app/assets/javascripts/ingredients.js.coffee create mode 100644 app/assets/stylesheets/ingredients.css.scss create mode 100644 app/controllers/ingredients_controller.rb create mode 100644 app/helpers/ingredients_helper.rb create mode 100644 test/controllers/ingredients_controller_test.rb create mode 100644 test/helpers/ingredients_helper_test.rb diff --git a/app/assets/javascripts/ingredients.js.coffee b/app/assets/javascripts/ingredients.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/ingredients.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/ingredients.css.scss b/app/assets/stylesheets/ingredients.css.scss new file mode 100644 index 0000000..1953e14 --- /dev/null +++ b/app/assets/stylesheets/ingredients.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Ingredients controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/ingredients_controller.rb b/app/controllers/ingredients_controller.rb new file mode 100644 index 0000000..d14114a --- /dev/null +++ b/app/controllers/ingredients_controller.rb @@ -0,0 +1,25 @@ +class IngredientsController < ApplicationController + + def show + end + + def create + @ingredient = Ingredient.new(ingredient_params) + + respond_to do |format| + if @ingredient.save + format.html { redirect_to @ingredient, notice: 'Menu item was successfully created.' } + format.json { render action: 'show', status: :created, location: @ingredient } + else + format.html { render action: 'new' } + format.json { render json: @ingredient.errors, status: :unprocessable_entity } + end + end + end + + private + + def ingredient_params + params.require(:ingredient).permit(:name) + end +end diff --git a/app/helpers/ingredients_helper.rb b/app/helpers/ingredients_helper.rb new file mode 100644 index 0000000..dd54783 --- /dev/null +++ b/app/helpers/ingredients_helper.rb @@ -0,0 +1,2 @@ +module IngredientsHelper +end diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index 5f772b2..62e0fe6 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -4,4 +4,6 @@ class MenuItem < ActiveRecord::Base validates :name, presence: true validates :price, presence: true + + accepts_nested_attributes_for :ingredients end diff --git a/app/views/menu_items/_form.html.erb b/app/views/menu_items/_form.html.erb index d17a090..7114bee 100644 --- a/app/views/menu_items/_form.html.erb +++ b/app/views/menu_items/_form.html.erb @@ -11,6 +11,7 @@ <% end %> <%= f.text_field :name %> + <%= f.text_field :price %>
<%= f.submit %>
diff --git a/app/views/menu_items/index.html.erb b/app/views/menu_items/index.html.erb index b1db6a9..9fec0a4 100644 --- a/app/views/menu_items/index.html.erb +++ b/app/views/menu_items/index.html.erb @@ -3,6 +3,8 @@ + + @@ -12,7 +14,8 @@ <% @menu_items.each do |menu_item| %> - + + diff --git a/app/views/menu_items/show.html.erb b/app/views/menu_items/show.html.erb index 1a2fd70..65314c2 100644 --- a/app/views/menu_items/show.html.erb +++ b/app/views/menu_items/show.html.erb @@ -1,4 +1,12 @@

<%= notice %>

+

<%= @menu_item.name %>

+
    +

    Ingredients:

    + <% @ingredients.each do |ingredient| %> +
  • <%= ingredient.name %>
  • + <% end %> +
+ <%= 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 2561082..789be4c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,11 +1,6 @@ Makerbistro::Application.routes.draw do - - root 'menu_items#index' - resources :menu_items do - recources :ingredients + resources :ingredients end - resources :ingredients - end diff --git a/test/controllers/ingredients_controller_test.rb b/test/controllers/ingredients_controller_test.rb new file mode 100644 index 0000000..8bce723 --- /dev/null +++ b/test/controllers/ingredients_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class IngredientsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/helpers/ingredients_helper_test.rb b/test/helpers/ingredients_helper_test.rb new file mode 100644 index 0000000..fc19ac4 --- /dev/null +++ b/test/helpers/ingredients_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class IngredientsHelperTest < ActionView::TestCase +end From 7c6d2315be153855006f0ac9c9fba8bd8c358d0b Mon Sep 17 00:00:00 2001 From: bangner Date: Mon, 14 Oct 2013 00:40:08 -0500 Subject: [PATCH 7/9] add examples into seed file --- app/controllers/ingredients_controller.rb | 3 ++- app/models/menu_item.rb | 1 - app/views/menu_items/_form.html.erb | 10 ++++++-- .../menu_items/_ingredient_form.html.erb | 17 +++++++++++++ app/views/menu_items/index.html.erb | 8 +++--- config/routes.rb | 3 +++ db/seeds.rb | 25 +++++++++++++++++++ 7 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 app/views/menu_items/_ingredient_form.html.erb diff --git a/app/controllers/ingredients_controller.rb b/app/controllers/ingredients_controller.rb index d14114a..dc07508 100644 --- a/app/controllers/ingredients_controller.rb +++ b/app/controllers/ingredients_controller.rb @@ -1,6 +1,7 @@ class IngredientsController < ApplicationController def show + @ingredients = Ingredient.all end def create @@ -8,7 +9,7 @@ def create respond_to do |format| if @ingredient.save - format.html { redirect_to @ingredient, notice: 'Menu item was successfully created.' } + format.html { redirect_to @ingredient, notice: 'Ingredient was successfully created.' } format.json { render action: 'show', status: :created, location: @ingredient } else format.html { render action: 'new' } diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index 62e0fe6..e618420 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -3,7 +3,6 @@ class MenuItem < ActiveRecord::Base has_many :ingredients, :through => :recipe validates :name, presence: true - validates :price, presence: true accepts_nested_attributes_for :ingredients end diff --git a/app/views/menu_items/_form.html.erb b/app/views/menu_items/_form.html.erb index 7114bee..f8a2f2a 100644 --- a/app/views/menu_items/_form.html.erb +++ b/app/views/menu_items/_form.html.erb @@ -10,8 +10,14 @@ <% end %> - <%= f.text_field :name %> - <%= f.text_field :price %> + + <%= f.text_field :name, :placeholder => "Item Name" %> + <%= f.text_field :price, :placeholder => "Item Price" %> + <% @menu_item.ingredients.each do |ingredient| %> + <%= f.fields_for "ingredients[]", ingredient do |ingredient_form| %> + <%= ingredient_form.text_field :name %> + <% end %> + <% end %>
<%= f.submit %>
diff --git a/app/views/menu_items/_ingredient_form.html.erb b/app/views/menu_items/_ingredient_form.html.erb new file mode 100644 index 0000000..fbc9568 --- /dev/null +++ b/app/views/menu_items/_ingredient_form.html.erb @@ -0,0 +1,17 @@ +<%= form_for(@ingredient) do |f| %> + <% if @ingredient.errors.any? %> +
+

<%= pluralize(@ingredient.errors.count, "error") %> prohibited this ingredient from being saved:

+ +
    + <% @ingredient.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + <%= f.text_field :name, :placeholder => "Ingredient" %> +
+ <%= f.submit %> +
+<% end %> \ No newline at end of file diff --git a/app/views/menu_items/index.html.erb b/app/views/menu_items/index.html.erb index 9fec0a4..8a5df44 100644 --- a/app/views/menu_items/index.html.erb +++ b/app/views/menu_items/index.html.erb @@ -5,9 +5,10 @@
- - - + + + + @@ -16,6 +17,7 @@ + diff --git a/config/routes.rb b/config/routes.rb index 789be4c..bd8790d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,4 +3,7 @@ resources :ingredients end + resource :ingredients + + root "menu_item#index" end diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e8..fd96b54 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,28 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) + + +mi1 = MenuItem.create(name: "Pizza", price: "10") +mi2 = MenuItem.create(name: "Hot Dog", price: "15") +mi3 = MenuItem.create(name: "Burger", price: "12") +mi4 = MenuItem.create(name: "Salad", price: "5") + +i1 = Ingredient.create(name:"Bread") +i2 = Ingredient.create(name:"Meat") +i3 = Ingredient.create(name:"Lettuce") +i4 = Ingredient.create(name:"Veggies") +i5 = Ingredient.create(name:"Dough") + +Recipe.create(menu_item: mi1, ingredient: i5) +Recipe.create(menu_item: mi1, ingredient: i2) + + +Recipe.create(menu_item: mi2, ingredient: i1) +Recipe.create(menu_item: mi2, ingredient: i2) + +Recipe.create(menu_item: mi3, ingredient: i1) +Recipe.create(menu_item: mi3, ingredient: i2) + +Recipe.create(menu_item: mi4, ingredient: i3) +Recipe.create(menu_item: mi4, ingredient: i4) \ No newline at end of file From 959db617e5fdc7d58fb34d70723dea7c0971e5dc Mon Sep 17 00:00:00 2001 From: bangner Date: Mon, 14 Oct 2013 01:04:14 -0500 Subject: [PATCH 8/9] fix form to include ingredients when editing --- app/views/menu_items/_form.html.erb | 4 ++-- ..._ingredient_form.html.erb => _ingredient.form.html.erb} | 1 + app/views/menu_items/index.html.erb | 2 +- app/views/menu_items/show.html.erb | 7 +++---- 4 files changed, 7 insertions(+), 7 deletions(-) rename app/views/menu_items/{_ingredient_form.html.erb => _ingredient.form.html.erb} (99%) diff --git a/app/views/menu_items/_form.html.erb b/app/views/menu_items/_form.html.erb index f8a2f2a..e7a2b0b 100644 --- a/app/views/menu_items/_form.html.erb +++ b/app/views/menu_items/_form.html.erb @@ -16,8 +16,8 @@ <% @menu_item.ingredients.each do |ingredient| %> <%= f.fields_for "ingredients[]", ingredient do |ingredient_form| %> <%= ingredient_form.text_field :name %> - <% end %> - <% end %> + <% end %> + <% end %>
<%= f.submit %>
diff --git a/app/views/menu_items/_ingredient_form.html.erb b/app/views/menu_items/_ingredient.form.html.erb similarity index 99% rename from app/views/menu_items/_ingredient_form.html.erb rename to app/views/menu_items/_ingredient.form.html.erb index fbc9568..70f19f2 100644 --- a/app/views/menu_items/_ingredient_form.html.erb +++ b/app/views/menu_items/_ingredient.form.html.erb @@ -10,6 +10,7 @@ <% end %> + <%= f.text_field :name, :placeholder => "Ingredient" %>
<%= f.submit %> diff --git a/app/views/menu_items/index.html.erb b/app/views/menu_items/index.html.erb index 8a5df44..307cabb 100644 --- a/app/views/menu_items/index.html.erb +++ b/app/views/menu_items/index.html.erb @@ -8,7 +8,7 @@
- + diff --git a/app/views/menu_items/show.html.erb b/app/views/menu_items/show.html.erb index 65314c2..18ca523 100644 --- a/app/views/menu_items/show.html.erb +++ b/app/views/menu_items/show.html.erb @@ -1,12 +1,11 @@

<%= notice %>

-

<%= @menu_item.name %>

-
    +

    <%= @menu_item.name.titleize %>

    +

    Price:<%= number_to_currency @menu_item.price %>

    Ingredients:

    <% @ingredients.each do |ingredient| %>
  • <%= ingredient.name %>
  • - <% end %> -
+<% end %> <%= link_to 'Edit', edit_menu_item_path(@menu_item) %> | <%= link_to 'Back', menu_items_path %> From b6b90bd674e8148afd8c9d665a32afa0c61bc345 Mon Sep 17 00:00:00 2001 From: bangner Date: Mon, 14 Oct 2013 01:20:21 -0500 Subject: [PATCH 9/9] cant get ingredients to print our properly on the index page --- app/controllers/menu_items_controller.rb | 1 + app/views/menu_items/index.html.erb | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/menu_items_controller.rb b/app/controllers/menu_items_controller.rb index 449b3ba..698c822 100644 --- a/app/controllers/menu_items_controller.rb +++ b/app/controllers/menu_items_controller.rb @@ -5,6 +5,7 @@ class MenuItemsController < ApplicationController # GET /menu_items.json def index @menu_items = MenuItem.all + @ingredients = Ingredient.all end # GET /menu_items/1 diff --git a/app/views/menu_items/index.html.erb b/app/views/menu_items/index.html.erb index 307cabb..8f7a133 100644 --- a/app/views/menu_items/index.html.erb +++ b/app/views/menu_items/index.html.erb @@ -17,7 +17,9 @@ - + + <% end %>
Item Name:Item Price:

<%= menu_item.name %>

<%= menu_item.name.titleize %>

<%= number_to_currency menu_item.price %>

<%= link_to 'Show', menu_item %> <%= link_to 'Edit', edit_menu_item_path(menu_item) %> <%= link_to 'Destroy', menu_item, method: :delete, data: { confirm: 'Are you sure?' } %>
Item Name: Item Price:Ingredients:ShowEditDelete

<%= menu_item.name.titleize %>

<%= number_to_currency menu_item.price %>

<%= menu_item.ingredients.all %>

<%= link_to 'Show', menu_item %> <%= link_to 'Edit', edit_menu_item_path(menu_item) %> <%= link_to 'Destroy', menu_item, method: :delete, data: { confirm: 'Are you sure?' } %>Ingredients: Show EditDelete

<%= menu_item.name.titleize %>

<%= number_to_currency menu_item.price %>

<%= menu_item.ingredients.all %>

<% @ingredients.each do |ingredient| %> +
  • <%= ingredient.name %>
  • <%= link_to 'Show', menu_item %> <%= link_to 'Edit', edit_menu_item_path(menu_item) %> <%= link_to 'Destroy', menu_item, method: :delete, data: { confirm: 'Are you sure?' } %>