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
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ group :doc do
gem 'sdoc', require: false
end

gem 'hirb'
gem 'haml'
gem 'simple_form'

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

Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -86,6 +89,9 @@ GEM
sdoc (0.3.20)
json (>= 1.1.3)
rdoc (~> 3.10)
simple_form (3.0.0)
actionpack (>= 4.0.0, < 4.1)
activemodel (>= 4.0.0, < 4.1)
slop (3.4.6)
sprockets (2.10.0)
hike (~> 1.2)
Expand Down Expand Up @@ -116,12 +122,15 @@ PLATFORMS

DEPENDENCIES
coffee-rails (~> 4.0.0)
haml
hirb
jbuilder (~> 1.2)
jquery-rails
pry
rails (= 4.0.0)
sass-rails (~> 4.0.0)
sdoc
simple_form
sqlite3
turbolinks
uglifier (>= 1.3.0)
8 changes: 8 additions & 0 deletions app/controllers/menu_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ class MenuItemsController < ApplicationController
# GET /menu_items.json
def index
@menu_items = MenuItem.all
@menu_item = MenuItem.new
end

# GET /menu_items/1
# GET /menu_items/1.json
def show
if params[:ingredient] != nil
@menu_item.ingredients.create(ingredient_params)
end
end

# GET /menu_items/new
Expand Down Expand Up @@ -71,4 +75,8 @@ def set_menu_item
def menu_item_params
params.require(:menu_item).permit(:name)
end

def ingredient_params
params[:ingredient].permit(:name)
end
end
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
14 changes: 9 additions & 5 deletions app/views/menu_items/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<h1>Listing menu_items</h1>
<h1>Listing of Menu Items</h1>

<%= render "form" %>

<table>
<thead>
Expand All @@ -16,11 +18,13 @@
<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>
<td>
<ul>
<% menu_item.ingredients.all.each do |ingredient| %>
<li><%= ingredient.name %></li>
<% end %>
</ul>
</tr>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New Menu item', new_menu_item_path %>
4 changes: 0 additions & 4 deletions app/views/menu_items/show.html.erb

This file was deleted.

12 changes: 12 additions & 0 deletions app/views/menu_items/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
%h2= @menu_item.name
%ul
-@menu_item.ingredients.all.each do |ingredient|
%li=ingredient.name

=simple_form_for @menu_item.ingredients.new do |f|
=f.input :name, placeholder: "new ingredient!", :input_html => {:maxlength => 30, :size => 40}
=f.button :submit

= link_to 'Edit', edit_menu_item_path(@menu_item)
|
= link_to 'Back', menu_items_path
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Makerbistro::Application.routes.draw do
resources :menu_items

post "/menu_items/:id" => "menu_items#show", as: "ingredients"
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20131011191357_create_recipes.rb
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 :name

t.timestamps
end
end
end
9 changes: 9 additions & 0 deletions db/migrate/20131011191405_create_ingredients.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateIngredients < ActiveRecord::Migration
def change
create_table :ingredients do |t|
t.string :name

t.timestamps
end
end
end
6 changes: 6 additions & 0 deletions db/migrate/20131011191433_add_recipes_ref_menu_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddRecipesRefMenuItem < ActiveRecord::Migration
def change
add_reference :recipes, :ingredient, index: true
add_reference :recipes, :menu_item, index: true
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: 20131011191433) 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.datetime "created_at"
t.datetime "updated_at"
end

create_table "recipes", force: true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "ingredient_id"
t.integer "menu_item_id"
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
7 changes: 7 additions & 0 deletions test/fixtures/ingredients.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html

one:
name: MyString

two:
name: MyString
7 changes: 7 additions & 0 deletions test/fixtures/recipes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html

one:
name: MyString

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

class IngredientTest < 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