diff --git a/.gitignore b/.gitignore
index b31dffd..c59fb6d 100755
--- a/.gitignore
+++ b/.gitignore
@@ -14,6 +14,8 @@
/log/*.log
/tmp
+*.swp
+
# Ignore coverage
coverage/
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..00c3614
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,29 @@
+FROM phusion/passenger-ruby21:0.9.12
+
+ENV HOME /root
+
+
+
+CMD ["bash"]
+CMD ["/sbin/my_init"]
+
+RUN rm -f /etc/service/nginx/down
+
+RUN rm /etc/nginx/sites-enabled/default
+
+ADD nginx.conf /etc/nginx/sites-enabled/webapp.conf
+
+RUN mkdir /home/app/webapp
+
+WORKDIR /tmp
+Add Gemfile /tmp/
+Add Gemfile.lock /tmp/
+RUN bundle install
+
+ADD . /home/app/webapp
+RUN cd /home/app/webapp && rake db:migrate
+
+RUN chown app:app -R /home/app/webapp
+RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
+
+
diff --git a/Gemfile b/Gemfile
index 9d9cd02..5dfe2fc 100755
--- a/Gemfile
+++ b/Gemfile
@@ -16,6 +16,7 @@ gem 'will_paginate', '~> 3.0'
gem 'will_paginate-bootstrap'
gem 'jquery-rails'
gem 'pundit'
+gem 'pg'
# Gems used only for assets and not required
# in production environments by default.
diff --git a/Gemfile.lock b/Gemfile.lock
index 41afb60..6db0c59 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -134,6 +134,7 @@ GEM
nokogiri (1.6.5)
mini_portile (~> 0.6.0)
orm_adapter (0.5.0)
+ pg (0.18.1)
protected_attributes (1.0.8)
activemodel (>= 4.0.1, < 5.0)
pry (0.10.1)
@@ -267,6 +268,7 @@ DEPENDENCIES
jquery-rails
launchy
mini_magick
+ pg
protected_attributes
pundit
rails
diff --git a/app/assets/javascripts/locations.coffee b/app/assets/javascripts/locations.coffee
new file mode 100644
index 0000000..24f83d1
--- /dev/null
+++ b/app/assets/javascripts/locations.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/locations.scss b/app/assets/stylesheets/locations.scss
new file mode 100644
index 0000000..b6e6e3a
--- /dev/null
+++ b/app/assets/stylesheets/locations.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Locations controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss
new file mode 100644
index 0000000..6ec6a8f
--- /dev/null
+++ b/app/assets/stylesheets/scaffolds.scss
@@ -0,0 +1,69 @@
+body {
+ background-color: #fff;
+ color: #333;
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px;
+}
+
+a {
+ color: #000;
+ &:visited {
+ color: #666;
+ }
+ &:hover {
+ color: #fff;
+ background-color: #000;
+ }
+}
+
+div {
+ &.field, &.actions {
+ margin-bottom: 10px;
+ }
+}
+
+#notice {
+ color: green;
+}
+
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table;
+}
+
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff;
+ }
+ ul li {
+ font-size: 12px;
+ list-style: square;
+ }
+}
diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb
index 3d2c120..26be1a0 100755
--- a/app/controllers/items_controller.rb
+++ b/app/controllers/items_controller.rb
@@ -22,6 +22,7 @@ def show
# GET /items/new
# GET /items/new.json
def new
+
@item = Item.new
respond_to do |format|
@@ -38,6 +39,7 @@ def edit
# POST /items
# POST /items.json
def create
+
@item = Item.new(params[:item])
respond_to do |format|
diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb
new file mode 100644
index 0000000..2eeac23
--- /dev/null
+++ b/app/controllers/locations_controller.rb
@@ -0,0 +1,49 @@
+class LocationsController < ApplicationController
+ before_action :set_location, only: [:show, :edit, :update, :destroy]
+
+ respond_to :html
+
+ def index
+ @locations = Location.all
+ respond_with(@locations)
+ end
+
+ def show
+
+ @items = @location.items
+ respond_with(@location, @items)
+ end
+
+ def new
+ @location = Location.new
+ respond_with(@location)
+ end
+
+ def edit
+ end
+
+ def create
+ @location = Location.new(location_params)
+ @location.save
+ respond_with(@location)
+ end
+
+ def update
+ @location.update(location_params)
+ respond_with(@location)
+ end
+
+ def destroy
+ @location.destroy
+ respond_with(@location)
+ end
+
+ private
+ def set_location
+ @location = Location.find(params[:id])
+ end
+
+ def location_params
+ params.require(:location).permit(:name)
+ end
+end
diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb
new file mode 100644
index 0000000..46f9428
--- /dev/null
+++ b/app/helpers/locations_helper.rb
@@ -0,0 +1,2 @@
+module LocationsHelper
+end
diff --git a/app/models/item.rb b/app/models/item.rb
index a4d846f..d99e9fb 100755
--- a/app/models/item.rb
+++ b/app/models/item.rb
@@ -1,11 +1,13 @@
class Item < ActiveRecord::Base
mount_uploader :picture, PictureUploader
- attr_accessible :description, :location, :name, :picture, :product_model_number, :vendor_part_number, :quantity, :unit_value, :vendor_url, :value, :vendor_name, :category
+ attr_accessible :description, :location, :name, :picture, :product_model_number, :vendor_part_number, :quantity, :unit_value, :vendor_url, :value, :vendor_name, :category, :location_id
self.per_page = 25
belongs_to :item
+belongs_to :location
after_save :update_value
+accepts_nested_attributes_for :location
protected
def update_value
diff --git a/app/models/location.rb b/app/models/location.rb
new file mode 100644
index 0000000..41b2b4e
--- /dev/null
+++ b/app/models/location.rb
@@ -0,0 +1,6 @@
+class Location < ActiveRecord::Base
+
+attr_accessible :name
+
+has_many :items
+end
diff --git a/app/views/items/._form.html.erb.swp b/app/views/items/._form.html.erb.swp
new file mode 100644
index 0000000..a25e419
Binary files /dev/null and b/app/views/items/._form.html.erb.swp differ
diff --git a/app/views/items/_form.html.erb b/app/views/items/_form.html.erb
index 5379be1..80b9545 100755
--- a/app/views/items/_form.html.erb
+++ b/app/views/items/_form.html.erb
@@ -65,7 +65,7 @@
diff --git a/app/views/items/index.html.erb b/app/views/items/index.html.erb
index 40d66e1..625014d 100755
--- a/app/views/items/index.html.erb
+++ b/app/views/items/index.html.erb
@@ -29,7 +29,7 @@
<%= number_to_currency(item.unit_value, :unit => "$") %> |
<%= number_to_currency(item.value, :unit => "$") %> |
<%= item.vendor_name %> |
- <%= item.location %> |
+ <%= item.location.name %> |
<%= item.category %> |
<%= link_to '', edit_item_path(item), :class=>"fa fa-edit" %> | <%= link_to content_tag(:i,nil, :class=>"fa fa-trash-o"), item, data: {confirm: 'Are you sure you want to delete this item?'}, method: :delete %>
|
diff --git a/app/views/items/show.html.erb b/app/views/items/show.html.erb
index 01060be..756fdad 100755
--- a/app/views/items/show.html.erb
+++ b/app/views/items/show.html.erb
@@ -55,7 +55,7 @@
Location
-
<%= @item.location %>
+
<%= @item.location.name %>
diff --git a/app/views/locations/_form.html.erb b/app/views/locations/_form.html.erb
new file mode 100644
index 0000000..7dc7fca
--- /dev/null
+++ b/app/views/locations/_form.html.erb
@@ -0,0 +1,21 @@
+<%= form_for(@location) do |f| %>
+ <% if @location.errors.any? %>
+
+
<%= pluralize(@location.errors.count, "error") %> prohibited this location from being saved:
+
+
+ <% @location.errors.full_messages.each do |message| %>
+ - <%= message %>
+ <% end %>
+
+
+ <% end %>
+
+
+ <%= f.label :name %>
+ <%= f.text_field :name %>
+
+
+ <%= f.submit %>
+
+<% end %>
diff --git a/app/views/locations/edit.html.erb b/app/views/locations/edit.html.erb
new file mode 100644
index 0000000..89278ed
--- /dev/null
+++ b/app/views/locations/edit.html.erb
@@ -0,0 +1,6 @@
+
Editing Location
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @location %> |
+<%= link_to 'Back', locations_path %>
diff --git a/app/views/locations/index.html.erb b/app/views/locations/index.html.erb
new file mode 100644
index 0000000..dc3e09c
--- /dev/null
+++ b/app/views/locations/index.html.erb
@@ -0,0 +1,27 @@
+
<%= notice %>
+
+
Listing Locations
+
+
+
+
+ Name |
+ |
+
+
+
+
+ <% @locations.each do |location| %>
+
+ <%= location.name %> |
+ <%= link_to 'Show', location %> |
+ <%= link_to 'Edit', edit_location_path(location) %> |
+ <%= link_to 'Destroy', location, method: :delete, data: { confirm: 'Are you sure?' } %> |
+
+ <% end %>
+
+
+
+
+
+<%= link_to 'New Location', new_location_path %>
diff --git a/app/views/locations/new.html.erb b/app/views/locations/new.html.erb
new file mode 100644
index 0000000..bdb0925
--- /dev/null
+++ b/app/views/locations/new.html.erb
@@ -0,0 +1,5 @@
+
New Location
+
+<%= render 'form' %>
+
+<%= link_to 'Back', locations_path %>
diff --git a/app/views/locations/show.html.erb b/app/views/locations/show.html.erb
new file mode 100644
index 0000000..d2646c9
--- /dev/null
+++ b/app/views/locations/show.html.erb
@@ -0,0 +1,18 @@
+
<%= notice %>
+
+
+ Name:
+ <%= @location.name %>
+
+
+
+Items in <%= @location.name %>
+
+
+<% @items.each do |i| %>
+- <%= i.name %>
+<% end %>
+
+
+<%= link_to 'Edit', edit_location_path(@location) %> |
+<%= link_to 'Back', locations_path %>
diff --git a/app/views/shared/_header.html.erb b/app/views/shared/_header.html.erb
index b5e1277..cb49126 100644
--- a/app/views/shared/_header.html.erb
+++ b/app/views/shared/_header.html.erb
@@ -24,6 +24,15 @@
<%= link_to 'New Item', new_item_path %>
+
+ Locations
+
+
+
+
diff --git a/config/routes.rb b/config/routes.rb
index f369903..8e07169 100755
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,9 +1,11 @@
Rims::Application.routes.draw do
+
get "welcome/index"
devise_for :users
root :to => 'welcome#index'
#root :to => redirect('/items')
resources :items
+ resources :locations
resources :users
end
diff --git a/db/migrate/20150310173115_add_location_to_item.rb b/db/migrate/20150310173115_add_location_to_item.rb
new file mode 100644
index 0000000..996ce10
--- /dev/null
+++ b/db/migrate/20150310173115_add_location_to_item.rb
@@ -0,0 +1,9 @@
+class AddLocationToItem < ActiveRecord::Migration
+ def change
+ remove_column :items, :location
+ add_reference :items, :location, index: true
+ add_foreign_key :items, :locations
+
+
+ end
+end
diff --git a/db/migrate/20150310173414_create_locations.rb b/db/migrate/20150310173414_create_locations.rb
new file mode 100644
index 0000000..486dd2e
--- /dev/null
+++ b/db/migrate/20150310173414_create_locations.rb
@@ -0,0 +1,9 @@
+class CreateLocations < ActiveRecord::Migration
+ def change
+ create_table :locations do |t|
+ t.string :name
+
+ t.timestamps null: false
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index f33168a..e79b926 100755
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20140412010617) do
+ActiveRecord::Schema.define(version: 20150310173414) do
create_table "items", force: :cascade do |t|
t.text "name"
@@ -25,9 +25,17 @@
t.string "picture"
t.text "vendor_url"
t.text "category"
- t.string "location"
t.datetime "created_at"
t.datetime "updated_at"
+ t.integer "location_id"
+ end
+
+ add_index "items", ["location_id"], name: "index_items_on_location_id"
+
+ create_table "locations", force: :cascade do |t|
+ t.string "name"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
end
create_table "users", force: :cascade do |t|
diff --git a/nginx.conf b/nginx.conf
new file mode 100644
index 0000000..5431613
--- /dev/null
+++ b/nginx.conf
@@ -0,0 +1,11 @@
+server {
+listen 80;
+root /home/app/webapp/public;
+
+passenger_enabled on;
+passenger_user app;
+
+passenger_ruby /usr/bin/ruby2.1;
+}
+
+
diff --git a/spec/controllers/locations_controller_spec.rb b/spec/controllers/locations_controller_spec.rb
new file mode 100644
index 0000000..e3a7f3f
--- /dev/null
+++ b/spec/controllers/locations_controller_spec.rb
@@ -0,0 +1,159 @@
+require 'rails_helper'
+
+# This spec was generated by rspec-rails when you ran the scaffold generator.
+# It demonstrates how one might use RSpec to specify the controller code that
+# was generated by Rails when you ran the scaffold generator.
+#
+# It assumes that the implementation code is generated by the rails scaffold
+# generator. If you are using any extension libraries to generate different
+# controller code, this generated spec may or may not pass.
+#
+# It only uses APIs available in rails and/or rspec-rails. There are a number
+# of tools you can use to make these specs even more expressive, but we're
+# sticking to rails and rspec-rails APIs to keep things simple and stable.
+#
+# Compared to earlier versions of this generator, there is very limited use of
+# stubs and message expectations in this spec. Stubs are only used when there
+# is no simpler way to get a handle on the object needed for the example.
+# Message expectations are only used when there is no simpler way to specify
+# that an instance is receiving a specific message.
+
+RSpec.describe LocationsController, :type => :controller do
+
+ # This should return the minimal set of attributes required to create a valid
+ # Location. As you add validations to Location, be sure to
+ # adjust the attributes here as well.
+ let(:valid_attributes) {
+ skip("Add a hash of attributes valid for your model")
+ }
+
+ let(:invalid_attributes) {
+ skip("Add a hash of attributes invalid for your model")
+ }
+
+ # This should return the minimal set of values that should be in the session
+ # in order to pass any filters (e.g. authentication) defined in
+ # LocationsController. Be sure to keep this updated too.
+ let(:valid_session) { {} }
+
+ describe "GET index" do
+ it "assigns all locations as @locations" do
+ location = Location.create! valid_attributes
+ get :index, {}, valid_session
+ expect(assigns(:locations)).to eq([location])
+ end
+ end
+
+ describe "GET show" do
+ it "assigns the requested location as @location" do
+ location = Location.create! valid_attributes
+ get :show, {:id => location.to_param}, valid_session
+ expect(assigns(:location)).to eq(location)
+ end
+ end
+
+ describe "GET new" do
+ it "assigns a new location as @location" do
+ get :new, {}, valid_session
+ expect(assigns(:location)).to be_a_new(Location)
+ end
+ end
+
+ describe "GET edit" do
+ it "assigns the requested location as @location" do
+ location = Location.create! valid_attributes
+ get :edit, {:id => location.to_param}, valid_session
+ expect(assigns(:location)).to eq(location)
+ end
+ end
+
+ describe "POST create" do
+ describe "with valid params" do
+ it "creates a new Location" do
+ expect {
+ post :create, {:location => valid_attributes}, valid_session
+ }.to change(Location, :count).by(1)
+ end
+
+ it "assigns a newly created location as @location" do
+ post :create, {:location => valid_attributes}, valid_session
+ expect(assigns(:location)).to be_a(Location)
+ expect(assigns(:location)).to be_persisted
+ end
+
+ it "redirects to the created location" do
+ post :create, {:location => valid_attributes}, valid_session
+ expect(response).to redirect_to(Location.last)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns a newly created but unsaved location as @location" do
+ post :create, {:location => invalid_attributes}, valid_session
+ expect(assigns(:location)).to be_a_new(Location)
+ end
+
+ it "re-renders the 'new' template" do
+ post :create, {:location => invalid_attributes}, valid_session
+ expect(response).to render_template("new")
+ end
+ end
+ end
+
+ describe "PUT update" do
+ describe "with valid params" do
+ let(:new_attributes) {
+ skip("Add a hash of attributes valid for your model")
+ }
+
+ it "updates the requested location" do
+ location = Location.create! valid_attributes
+ put :update, {:id => location.to_param, :location => new_attributes}, valid_session
+ location.reload
+ skip("Add assertions for updated state")
+ end
+
+ it "assigns the requested location as @location" do
+ location = Location.create! valid_attributes
+ put :update, {:id => location.to_param, :location => valid_attributes}, valid_session
+ expect(assigns(:location)).to eq(location)
+ end
+
+ it "redirects to the location" do
+ location = Location.create! valid_attributes
+ put :update, {:id => location.to_param, :location => valid_attributes}, valid_session
+ expect(response).to redirect_to(location)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns the location as @location" do
+ location = Location.create! valid_attributes
+ put :update, {:id => location.to_param, :location => invalid_attributes}, valid_session
+ expect(assigns(:location)).to eq(location)
+ end
+
+ it "re-renders the 'edit' template" do
+ location = Location.create! valid_attributes
+ put :update, {:id => location.to_param, :location => invalid_attributes}, valid_session
+ expect(response).to render_template("edit")
+ end
+ end
+ end
+
+ describe "DELETE destroy" do
+ it "destroys the requested location" do
+ location = Location.create! valid_attributes
+ expect {
+ delete :destroy, {:id => location.to_param}, valid_session
+ }.to change(Location, :count).by(-1)
+ end
+
+ it "redirects to the locations list" do
+ location = Location.create! valid_attributes
+ delete :destroy, {:id => location.to_param}, valid_session
+ expect(response).to redirect_to(locations_url)
+ end
+ end
+
+end
diff --git a/spec/factories/locations.rb b/spec/factories/locations.rb
new file mode 100644
index 0000000..79ae5bc
--- /dev/null
+++ b/spec/factories/locations.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :location do
+ name "MyString"
+ end
+
+end
diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb
new file mode 100644
index 0000000..d953da2
--- /dev/null
+++ b/spec/models/location_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe Location, :type => :model do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
diff --git a/spec/requests/locations_spec.rb b/spec/requests/locations_spec.rb
new file mode 100644
index 0000000..a5f09b4
--- /dev/null
+++ b/spec/requests/locations_spec.rb
@@ -0,0 +1,10 @@
+require 'rails_helper'
+
+RSpec.describe "Locations", :type => :request do
+ describe "GET /locations" do
+ it "works! (now write some real specs)" do
+ get locations_path
+ expect(response).to have_http_status(200)
+ end
+ end
+end