From cea2544c155b3385d04b418c39bbebaeb393af94 Mon Sep 17 00:00:00 2001 From: Jesse Kevon Date: Fri, 11 Oct 2013 13:55:30 -0500 Subject: [PATCH 1/4] added migrations --- Gemfile | 2 + Gemfile.lock | 2 + app/models/ingredient.rb | 4 ++ app/models/menu_item.rb | 2 + app/models/recipe.rb | 4 ++ config/routes.rb | 54 ------------------- .../20131010155724_create_menu_items.rb | 1 + db/migrate/20131011162357_create_recipes.rb | 10 ++++ .../20131011162407_create_ingredients.rb | 9 ++++ db/schema.rb | 36 +++++++++++++ test/fixtures/ingredients.yml | 11 ++++ test/fixtures/recipes.yml | 11 ++++ test/models/ingredient_test.rb | 7 +++ test/models/recipe_test.rb | 7 +++ 14 files changed, 106 insertions(+), 54 deletions(-) create mode 100644 app/models/ingredient.rb create mode 100644 app/models/recipe.rb create mode 100644 db/migrate/20131011162357_create_recipes.rb create mode 100644 db/migrate/20131011162407_create_ingredients.rb create mode 100644 db/schema.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/Gemfile b/Gemfile index 24a30f0..5c95813 100644 --- a/Gemfile +++ b/Gemfile @@ -29,6 +29,8 @@ gem 'turbolinks' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 1.2' +gem 'hirb' + group :doc do # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', require: false 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/config/routes.rb b/config/routes.rb index 8320abf..774c9b2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,56 +1,2 @@ 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 - - # 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/20131010155724_create_menu_items.rb b/db/migrate/20131010155724_create_menu_items.rb index 8278a6c..77bcb0b 100644 --- a/db/migrate/20131010155724_create_menu_items.rb +++ b/db/migrate/20131010155724_create_menu_items.rb @@ -2,6 +2,7 @@ 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/20131011162357_create_recipes.rb b/db/migrate/20131011162357_create_recipes.rb new file mode 100644 index 0000000..bea2454 --- /dev/null +++ b/db/migrate/20131011162357_create_recipes.rb @@ -0,0 +1,10 @@ +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/20131011162407_create_ingredients.rb b/db/migrate/20131011162407_create_ingredients.rb new file mode 100644 index 0000000..0dba3ae --- /dev/null +++ b/db/migrate/20131011162407_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 new file mode 100644 index 0000000..314cc25 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,36 @@ +# 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: 20131011162407) 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/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 3f4fd029392adc1d98a8d731598fd37067a8910f Mon Sep 17 00:00:00 2001 From: Jesse Kevon Date: Fri, 11 Oct 2013 22:22:52 -0500 Subject: [PATCH 2/4] Created haml view file --- Gemfile | 2 ++ Gemfile.lock | 3 +++ app/assets/stylesheets/application.css | 18 +++++++++++++++++ app/models/menu_item.rb | 2 +- app/views/layouts/application.html.erb | 2 ++ app/views/menu_items/index.html.erb | 26 ------------------------- app/views/menu_items/index.html.haml | 23 ++++++++++++++++++++++ config/routes.rb | 7 +++++++ public/stitched_wool.png | Bin 0 -> 297 bytes 9 files changed, 56 insertions(+), 27 deletions(-) delete mode 100644 app/views/menu_items/index.html.erb create mode 100644 app/views/menu_items/index.html.haml create mode 100644 public/stitched_wool.png diff --git a/Gemfile b/Gemfile index 5c95813..05162fb 100644 --- a/Gemfile +++ b/Gemfile @@ -31,6 +31,8 @@ gem 'jbuilder', '~> 1.2' gem 'hirb' +gem 'haml' + group :doc do # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 22af6b1..30b7ae0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -38,6 +38,8 @@ 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) @@ -117,6 +119,7 @@ PLATFORMS DEPENDENCIES coffee-rails (~> 4.0.0) + haml hirb jbuilder (~> 1.2) jquery-rails diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 3192ec8..52ac257 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -1,3 +1,21 @@ +body { + background-color: #dbe3eb; +} + +h1 { + text-align: center; + font-family: molesk; + font-size: 3em; +} + +td { + text-align: center; +} + +a { + text-decoration: none; +} + /* * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index 37c3026..24e4f03 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -1,4 +1,4 @@ -class MenuItem < ActiveRecord::Base + class MenuItem < ActiveRecord::Base has_many :recipes has_many :ingredients, :through => :recipes end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 4bde935..c3794b6 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -8,6 +8,8 @@ +

MAKERSBISTRO

+ <%= yield %> diff --git a/app/views/menu_items/index.html.erb b/app/views/menu_items/index.html.erb deleted file mode 100644 index b1db6a9..0000000 --- a/app/views/menu_items/index.html.erb +++ /dev/null @@ -1,26 +0,0 @@ -

Listing menu_items

- - - - - - - - - - - - <% @menu_items.each do |menu_item| %> - - - - - - - <% end %> - -

<%= menu_item.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?' } %>
- -
- -<%= link_to 'New Menu item', new_menu_item_path %> diff --git a/app/views/menu_items/index.html.haml b/app/views/menu_items/index.html.haml new file mode 100644 index 0000000..59e3c4b --- /dev/null +++ b/app/views/menu_items/index.html.haml @@ -0,0 +1,23 @@ +%h1 Now Serving: + +%table + %thead + %tr + %th + %th + %th + %th + + %tbody + -@menu_items.each do |menu_item| + %tr + %td= menu_item.name + %td= menu_item.price + %td= link_to 'Show', menu_item + %td= link_to 'Edit', edit_menu_item_path(menu_item) + %td= link_to 'Destroy', menu_item, data: { method: :delete } + +%br + += link_to 'New Menu item', new_menu_item_path + diff --git a/config/routes.rb b/config/routes.rb index 774c9b2..e5126eb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,2 +1,9 @@ Makerbistro::Application.routes.draw do + resources :menu_items do + resources :recipes + end + + resources :ingredients, only: [:show] + + root 'menu_items#index' end diff --git a/public/stitched_wool.png b/public/stitched_wool.png new file mode 100644 index 0000000000000000000000000000000000000000..7698b4a24ffbf0558bd8062604024d0c0fa6c5c6 GIT binary patch literal 297 zcmeAS@N?(olHy`uVBq!ia0vp^4}iFVgBeJwvQO;eZ_cA3l8h_U+4;FP}eu{`m3Zr%#{WzkmPy`SUNl;_HA~_IkQFhE&{od-U1&2<|4JM;JU^{an^LB{Ts5Gn$Qh literal 0 HcmV?d00001 From 0f84483b5757ac2f28e11e31697dde2e288383b6 Mon Sep 17 00:00:00 2001 From: Jesse Kevon Date: Wed, 30 Oct 2013 11:13:11 -0500 Subject: [PATCH 3/4] Update README.rdoc --- README.rdoc | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/README.rdoc b/README.rdoc index dd4e97e..fcfc424 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,28 +1,5 @@ -== README - -This README would normally document whatever steps are necessary to get the -application up and running. - -Things you may want to cover: - -* Ruby version - -* System dependencies - -* Configuration - -* Database creation - -* Database initialization - -* How to run the test suite - -* Services (job queues, cache servers, search engines, etc.) - -* Deployment instructions - -* ... - - -Please feel free to use a different markup language if you do not plan to run -rake doc:app. +• Create a resturaunt menu using Ruby on Rails +• Homepage should list all menu items +• Each menu item should have a name, a price, and a list of ingredients +• User should be able to add menu items at the bottom of the homepage +• Technology: Ruby on Rails and Haml From f7fcccabbae6f6b7b204a6743e6729ef96cc91d3 Mon Sep 17 00:00:00 2001 From: Jesse Kevon Date: Wed, 30 Oct 2013 11:14:50 -0500 Subject: [PATCH 4/4] Update README.rdoc --- README.rdoc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rdoc b/README.rdoc index fcfc424..9a1eb00 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,5 +1,8 @@ • Create a resturaunt menu using Ruby on Rails + • Homepage should list all menu items + • Each menu item should have a name, a price, and a list of ingredients + • User should be able to add menu items at the bottom of the homepage • Technology: Ruby on Rails and Haml