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 @@
<%= f.label :location, class: "col-sm-3 control-label" %>
- <%= f.text_field :location, class: "form-control" %> + <%= collection_select(:item, :location_id, Location.all, :id, :name, {:selected => @item.location(:id), prompt: @item.location(:id) }) %>
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:

+ + +
+ <% 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

+ + + + + + + + + + + <% @locations.each do |location| %> + + + + + + + <% end %> + +
Name
<%= location.name %><%= link_to 'Show', location %><%= link_to 'Edit', edit_location_path(location) %><%= link_to 'Destroy', location, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= 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 %> + +

+ +<%= 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 %>
  • + + +