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
25 changes: 25 additions & 0 deletions .cimon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
services:
rails:
from: ruby:2.1.2
cache:
- /bundle
build:
- apt-get update
- apt-get install -y libqt4-dev pkg-config
- apt-get install -y nodejs postgresql-client sqlite3
- apt-get install -y curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev libxml2-dev libxslt-dev
- gem install bundler
postgres:
from: postgres

test:
prepare:
- bundle install --path /bundle
- bin/rake db:create
service: rails
folder: /app
cmd: "echo '%.......................%'"
env:
- RAILS_ENV=test
- RACK_ENV=test
- DATABASE_URL=postgres://postgres:mysecretpassword@127.0.0.1:5432/db
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ gem 'rails', '3.2.13'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'

# gem 'sqlite3'
gem 'pg'

# Gems used only for assets and not required
# in production environments by default.
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ GEM
treetop (~> 1.4.8)
mime-types (1.25)
multi_json (1.8.0)
pg (0.16.0)
polyglot (0.3.3)
rack (1.4.5)
rack-cache (1.2)
Expand Down Expand Up @@ -87,7 +88,6 @@ GEM
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.8)
thor (0.18.1)
tilt (1.4.1)
treetop (1.4.15)
Expand All @@ -104,7 +104,7 @@ PLATFORMS
DEPENDENCIES
coffee-rails (~> 3.2.1)
jquery-rails
pg
rails (= 3.2.13)
sass-rails (~> 3.2.3)
sqlite3
uglifier (>= 1.0.3)
3 changes: 3 additions & 0 deletions app/assets/javascripts/menus.js.coffee
Original file line number Diff line number Diff line change
@@ -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://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/menus.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Menus controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
55 changes: 55 additions & 0 deletions app/controllers/menus_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class MenusController < ApplicationController
respond_to :html, :js
before_filter :find_menu, only: [:show, :edit, :update, :destroy]

def show
respond_to do |format|
format.html # show.html.erb
format.json { render json: @menu }
end
end

def new
@menu = Menu.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @menu }
end
end

def edit
end

def create
@menu = Menu.create(params[:menu])
end

def update

respond_to do |format|
if @menu.update_attributes(params[:menu])
format.html { redirect_to @menu, notice: 'Menu was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @menu.errors, status: :unprocessable_entity }
end
end
end

def destroy
@menu.destroy

respond_to do |format|
format.html { redirect_to menus_url }
format.json { head :no_content }
end
end

private

def find_menu
@menu = Menu.find(params[:id])
end
end
53 changes: 12 additions & 41 deletions app/controllers/restaurants_controller.rb
Original file line number Diff line number Diff line change
@@ -1,83 +1,54 @@
class RestaurantsController < ApplicationController
# GET /restaurants
# GET /restaurants.json

before_filter :find_restaurant, only: [:show, :edit, :update, :destroy]

def index
@restaurants = Restaurant.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @restaurants }
end
end

# GET /restaurants/1
# GET /restaurants/1.json
def show
@restaurant = Restaurant.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @restaurant }
end
@menus = @restaurant.menus
end

# GET /restaurants/new
# GET /restaurants/new.json
def new
@restaurant = Restaurant.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @restaurant }
end
end

# GET /restaurants/1/edit
def edit
@restaurant = Restaurant.find(params[:id])
@menu = @restaurant.menus.new
end

# POST /restaurants
# POST /restaurants.json
def create
@restaurant = Restaurant.new(params[:restaurant])

respond_to do |format|
if @restaurant.save
format.html { redirect_to @restaurant, notice: 'Restaurant was successfully created.' }
format.json { render json: @restaurant, status: :created, location: @restaurant }
else
format.html { render action: "new" }
format.json { render json: @restaurant.errors, status: :unprocessable_entity }
end
end
end

# PUT /restaurants/1
# PUT /restaurants/1.json
def update
@restaurant = Restaurant.find(params[:id])

def update
respond_to do |format|
if @restaurant.update_attributes(params[:restaurant])
format.html { redirect_to @restaurant, notice: 'Restaurant was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @restaurant.errors, status: :unprocessable_entity }
end
end
end

# DELETE /restaurants/1
# DELETE /restaurants/1.json
def destroy
@restaurant = Restaurant.find(params[:id])
@restaurant.destroy

respond_to do |format|
format.html { redirect_to restaurants_url }
format.json { head :no_content }
end
end

private

def find_restaurant
@restaurant = Restaurant.find(params[:id])
end
end
2 changes: 2 additions & 0 deletions app/helpers/menus_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module MenusHelper
end
4 changes: 4 additions & 0 deletions app/models/menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Menu < ActiveRecord::Base
attr_accessible :title, :restaurant_id
belongs_to :restaurant
end
1 change: 1 addition & 0 deletions app/models/restaurant.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class Restaurant < ActiveRecord::Base
attr_accessible :building, :city, :description, :name, :phone, :street, :zip
has_many :menus
end
21 changes: 21 additions & 0 deletions app/views/menus/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<%= form_for(@menu) do |f| %>
<% if @menu.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@menu.errors.count, "error") %> prohibited this menu from being saved:</h2>

<ul>
<% @menu.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
14 changes: 14 additions & 0 deletions app/views/menus/_new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<h1>New menu</h1>
<%= form_for(@menu, remote: true) do |f| %>
<div class="field">
<%= f.hidden_field :restaurant_id, :value => @restaurant.id%>
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<%= @restaurant.inspect %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

<%= link_to 'Back', menus_path %>
1 change: 1 addition & 0 deletions app/views/menus/create.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alert('2');
6 changes: 6 additions & 0 deletions app/views/menus/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing menu</h1>

<%= render 'form' %>

<%= link_to 'Show', @menu %> |
<%= link_to 'Back', menus_path %>
23 changes: 23 additions & 0 deletions app/views/menus/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<h1>Listing menus</h1>

<table>
<tr>
<th>Title</th>
<th></th>
<th></th>
<th></th>
</tr>

<% @menus.each do |menu| %>
<tr>
<td><%= menu.title %></td>
<td><%= link_to 'Show', menu %></td>
<td><%= link_to 'Edit', edit_menu_path(menu) %></td>
<td><%= link_to 'Destroy', menu, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New Menu', new_menu_path %>
10 changes: 10 additions & 0 deletions app/views/menus/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p id="notice"><%= notice %></p>

<p>
<b>Title:</b>
<%= @menu.title %>
</p>


<%= link_to 'Edit', edit_menu_path(@menu) %> |
<%= link_to 'Back', menus_path %>
7 changes: 6 additions & 1 deletion app/views/restaurants/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
<%= render 'form' %>

<%= link_to 'Show', @restaurant %> |
<%= link_to 'Back', restaurants_path %>
<%= link_to 'Back', restaurants_path %> |
<p>
<%= @restaurant.menus.count %>
</p>

<%= render 'menus/new' %>
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Lunch::Application.routes.draw do
resources :menus
resources :restaurants

root to: "restaurants#index"


Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20131005143814_create_menus.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateMenus < ActiveRecord::Migration
def change
create_table :menus do |t|
t.string :title
t.integer :restaurant_id

t.timestamps
end
end
end
9 changes: 8 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20131003234938) do
ActiveRecord::Schema.define(:version => 20131005143814) do

create_table "menus", :force => true do |t|
t.string "title"
t.integer "restaurant_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

create_table "restaurants", :force => true do |t|
t.string "name"
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/menus.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:
title: MyString

two:
title: MyString
Loading