diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..fec39aa
Binary files /dev/null and b/.DS_Store differ
diff --git a/Gemfile b/Gemfile
index c6b7b16..c0e89c5 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,5 +1,6 @@
source 'https://rubygems.org'
-ruby '2.1.4'
+ruby '2.1.5'
+
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.7'
@@ -23,6 +24,9 @@ gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
+# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
+gem 'spring', group: :development
+
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
@@ -35,18 +39,16 @@ gem 'sdoc', '~> 0.4.0', group: :doc
# Use debugger
# gem 'debugger', group: [:development, :test]
-# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
-gem 'tzinfo-data', platforms: [:mingw, :mswin , :x64_mingw]
-
-
#bootstrap
gem 'bootstrap-sass', '3.2.0.0'
+#debug stuff
+gem 'byebug'
-#generate data
-gem 'faker', '1.4.2'
+#passwords
+gem 'bcrypt', '3.1.7'
#paginate stuff
gem 'will_paginate', '3.0.7'
-gem 'bootstrap-will_paginate', '0.0.10'
\ No newline at end of file
+gem 'bootstrap-will_paginate', '0.0.10'
diff --git a/Gemfile.lock b/Gemfile.lock
index 89a0498..12a9ee6 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -28,11 +28,16 @@ GEM
thread_safe (~> 0.1)
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
+ bcrypt (3.1.7)
bootstrap-sass (3.2.0.0)
sass (~> 3.2)
bootstrap-will_paginate (0.0.10)
will_paginate
builder (3.2.2)
+ byebug (3.5.1)
+ columnize (~> 0.8)
+ debugger-linecache (~> 1.2)
+ slop (~> 3.6)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
@@ -40,13 +45,13 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.8.0)
+ columnize (0.8.9)
+ debugger-linecache (1.2.0)
erubis (2.7.0)
execjs (2.2.2)
- faker (1.4.2)
- i18n (~> 0.5)
hike (1.2.3)
i18n (0.6.11)
- jbuilder (2.2.4)
+ jbuilder (2.2.5)
activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2)
jquery-rails (3.1.2)
@@ -56,7 +61,7 @@ GEM
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.4.3)
- minitest (5.4.2)
+ minitest (5.4.3)
multi_json (1.10.1)
rack (1.5.2)
rack-test (0.6.2)
@@ -88,6 +93,8 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
+ slop (3.6.0)
+ spring (1.2.0)
sprockets (2.11.3)
hike (~> 1.2)
multi_json (~> 1.0)
@@ -97,36 +104,35 @@ GEM
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
- sqlite3 (1.3.10-x64-mingw32)
+ sqlite3 (1.3.10)
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
- turbolinks (2.5.1)
+ turbolinks (2.5.2)
coffee-rails
tzinfo (1.2.2)
thread_safe (~> 0.1)
- tzinfo-data (1.2014.9)
- tzinfo (>= 1.0.0)
uglifier (2.5.3)
execjs (>= 0.3.0)
json (>= 1.8.0)
will_paginate (3.0.7)
PLATFORMS
- x64-mingw32
+ ruby
DEPENDENCIES
+ bcrypt (= 3.1.7)
bootstrap-sass (= 3.2.0.0)
bootstrap-will_paginate (= 0.0.10)
+ byebug
coffee-rails (~> 4.0.0)
- faker (= 1.4.2)
jbuilder (~> 2.0)
jquery-rails
rails (= 4.1.7)
sass-rails (~> 4.0.3)
sdoc (~> 0.4.0)
+ spring
sqlite3
turbolinks
- tzinfo-data
uglifier (>= 1.3.0)
will_paginate (= 3.0.7)
diff --git a/app/assets/javascripts/products.js.coffee b/app/assets/javascripts/products.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/products.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# 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/javascripts/sessions.js.coffee b/app/assets/javascripts/sessions.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/sessions.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# 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/javascripts/static_pages.js.coffee b/app/assets/javascripts/static_pages.js.coffee
deleted file mode 100644
index 24f83d1..0000000
--- a/app/assets/javascripts/static_pages.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# 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/application.css b/app/assets/stylesheets/application.css
index ef5e5eb..149333d 100644
--- a/app/assets/stylesheets/application.css
+++ b/app/assets/stylesheets/application.css
@@ -1,74 +1,3 @@
-@import "bootstrap-sprockets";
-@import "bootstrap";
-
-body {
- padding-top: 60px;
-}
-
-
-/* header */
-
-#logo {
- float: left;
- margin-right: 10px;
- font-size: 1.7em;
- color: #fff;
- text-transform: uppercase;
- letter-spacing: -1px;
- padding-top: 9px;
- font-weight: bold;
-}
-
-#logo:hover {
- color: #fff;
- text-decoration: none;
-}
-
-/* footer */
-
-footer {
- margin-top: 45px;
- padding-top: 5px;
- border-top: 1px solid #eaeaea;
- color: #777;
-}
-
-footer a {
- color: #555;
-}
-
-footer a:hover {
- color: #222;
-}
-
-footer small {
- float: left;
-}
-
-footer ul {
- float: right;
- list-style: none;
-}
-
-footer ul li {
- float: left;
- margin-left: 15px;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
@@ -84,3 +13,43 @@ footer ul li {
*= require_tree .
*= require_self
*/
+
+
+@import "bootstrap-sprockets";
+@import "bootstrap";
+
+/* mixins, variables, etc. */
+
+$gray-medium-light: #eaeaea;
+
+@mixin box_sizing {
+ -moz-box-sizing: border-box;
+ -webkit-box-sizing: border-box;
+ box-sizing: border-box;
+}
+.
+.
+.
+/* miscellaneous */
+
+.debug_dump {
+ clear: both;
+ float: left;
+ width: 100%;
+ margin-top: 45px;
+ @include box_sizing;
+}
+
+
+/* forms */
+
+input, textarea, select, .uneditable-input {
+ border: 1px solid #bbb;
+ width: 100%;
+ margin-bottom: 15px;
+ @include box_sizing;
+}
+
+input {
+ height: auto !important;
+}
diff --git a/app/assets/stylesheets/products.css.scss b/app/assets/stylesheets/products.css.scss
deleted file mode 100644
index bff386e..0000000
--- a/app/assets/stylesheets/products.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the Products 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/sessions.css.scss b/app/assets/stylesheets/sessions.css.scss
deleted file mode 100644
index ccb1ed2..0000000
--- a/app/assets/stylesheets/sessions.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the Sessions 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/static_pages.css.scss b/app/assets/stylesheets/static_pages.css.scss
deleted file mode 100644
index d55836c..0000000
--- a/app/assets/stylesheets/static_pages.css.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the StaticPages 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/users.css.scss b/app/assets/stylesheets/users.css.scss
index 31a2eac..442b185 100644
--- a/app/assets/stylesheets/users.css.scss
+++ b/app/assets/stylesheets/users.css.scss
@@ -1,3 +1,32 @@
// Place all the styles related to the Users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
+
+
+/* sidebar */
+
+aside {
+ section.user_info {
+ margin-top: 20px;
+ }
+ section {
+ padding: 10px 0;
+ margin-top: 20px;
+ &:first-child {
+ border: 0;
+ padding-top: 0;
+ }
+ span {
+ display: block;
+ margin-bottom: 3px;
+ line-height: 1;
+ }
+ h1 {
+ font-size: 1.4em;
+ text-align: left;
+ letter-spacing: -1px;
+ margin-bottom: 3px;
+ margin-top: 0px;
+ }
+ }
+}
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index a121071..f854d35 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -2,18 +2,6 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
- include SessionsHelper
- include ProductsHelper
- include OrdersHelper
- private
-
- # Confirms a logged-in user.
- def logged_in_user
- unless logged_in?
- store_location
- #flash[:danger] = "Please log in."
- redirect_to login_url
- end
- end
+ include OrdersHelper
end
diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb
index f0b5d1e..1f1ee7d 100644
--- a/app/controllers/orders_controller.rb
+++ b/app/controllers/orders_controller.rb
@@ -1,29 +1,37 @@
class OrdersController < ApplicationController
- before_action :logged_in_user, only: [ :destroy]
-
def new
-
+ @users = User.all
+ end
+
+ def create_session
+ user = User.find(params[:user_id])
+ if user
+ ordering(user)
+ redirect_to order_path
+ else
+ redirect_to overview_path
+ end
+ end
+
+ def order
+ @order = current_ordering_user.orders.build
+ end
+
+
+ def create
+ @order = current_ordering_user.orders.build(order_params)
+ if @order.save
+ flash[:success] = "order created!"
+ end_order
+ redirect_to overview_path
+ else
+ redirect_to overview_path
+ end
end
def destroy
- end
-
-
- def show
- @user = User.find(params[:id])
- @order = @user.orders.build
- end
-
- def create
- user = User.find( 3) #MUST BE FIXED
- @order = user.orders.build(order_params)
- if @order.save
- #@flash[:success] = "Micropost created!"
- redirect_to root_url
- else
- @logs = []
- render 'static_pages/home'
- end
+ end_order
+ redirect_to overview_path
end
private
@@ -31,6 +39,4 @@ class OrdersController < ApplicationController
def order_params
params.require(:order).permit(:products)
end
-
-
end
diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb
deleted file mode 100644
index eb747d2..0000000
--- a/app/controllers/products_controller.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-class ProductsController < ApplicationController
- def new
- @product = Product.new
- end
-
- def show
- @product = Product.find(params[:id])
- end
-
- def create
- @product = Product.new(product_params) # Not the final implementation!
- if @product.save
- redirect_to @product
- else
- render 'new'
- end
- end
-
- def edit
- @product = Product.find(params[:id])
- end
-
- def update
- @product = Product.find(params[:id])
- if @product.update_attributes(product_params)
- redirect_to @product
- else
- render 'edit'
- end
- end
-
-
-
-
- private
-
- def product_params
- params.require(:product).permit(:name, :sale_price, :purchase_price,
- :image_path)
- end
-end
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
deleted file mode 100644
index 7b05e78..0000000
--- a/app/controllers/sessions_controller.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-class SessionsController < ApplicationController
- def new
- end
-
- def create
- user = User.find_by(name: params[:session][:name])
- if user
- log_in user
- redirect_back_or user
- else
- #flash.now[:danger] = 'Invalid username'
- render 'new'
- end
- end
-
- def destroy
- log_out
- redirect_to root_url
- end
-
-end
diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb
deleted file mode 100644
index 159b7b6..0000000
--- a/app/controllers/static_pages_controller.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-class StaticPagesController < ApplicationController
- def home
- if logged_in?
- @order = current_user.orders.build if logged_in?
- @logs = current_user.feed.paginate(page: params[:page])
- end
- end
-
- def overview
- @users = User.all
- end
-
- def order
- end
-
- def help
- end
-
-end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 3b8a4f3..8db533a 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1,68 +1,30 @@
class UsersController < ApplicationController
- before_action :logged_in_user, only: [ :index, :edit, :update, :show]
- before_action :correct_user, only: [:edit, :update]
-
- def index
- @users = User.paginate(page: params[:page])
- end
-
-
def new
- @user = User.new
+ @user = User.new
end
def show
- @user = User.find(params[:id])
+ @user = User.find(params[:id])
@orders = @user.orders.paginate(page: params[:page])
end
def create
- @user = User.new(user_params)
- if @user.save
- log_in @user
- flash[:success] = "Welcome to the Sample App!"
- redirect_to @user
- else
- render 'new'
- end
- end
-
- def order
- @user = User.find(params[:id])
- end
-
- def edit
- @user = User.find(params[:id])
- end
-
- def update
- @user = User.find(params[:id])
- if @user.update_attributes(user_params)
+ @user = User.new(user_params)
+ if @user.save
redirect_to @user
else
- render 'edit'
+ render 'new'
end
end
+ def index
+ @users = User.all
+ end
+
private
- def user_params
- params.require(:user).permit(:name, :marks)
- end
-
- # Confirms a logged-in user.
- def logged_in_user
- unless logged_in?
- store_location
- flash[:danger] = "Please log in."
- redirect_to login_url
- end
- end
-
- # Confirms the correct user.
- def correct_user
- @user = User.find(params[:id])
- redirect_to(root_url) unless current_user?(@user)
- end
-
+ def user_params
+ params.require(:user).permit(:name, :last_name, :password,
+ :password_confirmation, :nickname)
+ end
end
diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb
index 6b5f214..8faf988 100644
--- a/app/helpers/orders_helper.rb
+++ b/app/helpers/orders_helper.rb
@@ -1,10 +1,20 @@
module OrdersHelper
- def select_user(user)
- selected_user = user.id
- end
+ def ordering(user)
+ session[:order_user_id] = user.id
+ end
+
+ def current_ordering_user
+ @current_ordering_user ||= User.find_by(id: session[:order_user_id])
+ end
+
+ def end_order
+ session.delete(:order_user_id)
+ @current_ordering_user = nil
+ end
+
+ def ordering?
+ !current_ordering_user.nil?
+ end
- def selected_user
- return selected_user
- end
end
diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb
deleted file mode 100644
index 6511824..0000000
--- a/app/helpers/products_helper.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module ProductsHelper
-
- def current_product?(product)
- product == current_product
- end
-end
diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb
deleted file mode 100644
index f98cd13..0000000
--- a/app/helpers/sessions_helper.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-module SessionsHelper
-
- def log_in(user)
- session[:user_id] = user.id
- end
-
- def current_user
- @current_user ||= User.find_by(id: session[:user_id])
- end
-
- def logged_in?
- !current_user.nil?
- end
-
- def log_out
- session.delete(:user_id)
- @current_user = nil
- end
-
- # Redirects to stored location (or to the default).
- def redirect_back_or(default)
- redirect_to(session[:forwarding_url] || default)
- session.delete(:forwarding_url)
- end
-
- # Stores the URL trying to be accessed.
- def store_location
- session[:forwarding_url] = request.url if request.get?
- end
-
-
- def current_user?(user)
- user == current_user
- end
-
-end
diff --git a/app/helpers/static_pages_helper.rb b/app/helpers/static_pages_helper.rb
deleted file mode 100644
index 2d63e79..0000000
--- a/app/helpers/static_pages_helper.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-module StaticPagesHelper
-end
diff --git a/app/models/order.rb b/app/models/order.rb
index a4090dd..e94fa0d 100644
--- a/app/models/order.rb
+++ b/app/models/order.rb
@@ -1,6 +1,4 @@
class Order < ActiveRecord::Base
- belongs_to :user
-
+ belongs_to :users
default_scope -> { order('created_at DESC') }
- validates :products, presence: true, length: { maximum: 140 }
end
diff --git a/app/models/product.rb b/app/models/product.rb
deleted file mode 100644
index c4527b9..0000000
--- a/app/models/product.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-class Product < ActiveRecord::Base
- after_initialize :init
-
-
- def init
- self.name ||= "FOOBAR"
- self.sale_price ||= 0
- self.purchase_price ||= 0
- self.image_path ||= "/" #paperclip gem
- end
-end
diff --git a/app/models/user.rb b/app/models/user.rb
index 84fb93f..3c791bb 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,18 +1,13 @@
class User < ActiveRecord::Base
- has_many :orders, dependent: :destroy
- after_initialize :init
+ has_many :orders
+ before_save :init
- validates :name, presence: true, length: { maximum: 50 },
- uniqueness: true
- def init
- self.marks ||= 0
- self.role ||= "user"
+
+ def init
+ self.balance ||= 0
end
- def feed
- # This is preliminary. See "Following users" for the full implementation.
- Order.where("user_id = ?", id)
- end
+ has_secure_password
end
diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb
deleted file mode 100644
index 9de717c..0000000
--- a/app/views/layouts/_footer.html.erb
+++ /dev/null
@@ -1,13 +0,0 @@
-
\ No newline at end of file
diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb
deleted file mode 100644
index dd62504..0000000
--- a/app/views/layouts/_header.html.erb
+++ /dev/null
@@ -1,33 +0,0 @@
-