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 @@ - \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 776fc08..cba19c6 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,18 +1,16 @@ - TaÞ + Tab002 <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> -<%= render 'layouts/header' %> -
- <%= yield %> - <%= render 'layouts/footer' %> -
+<%= yield %> + +<%= debug(params) if Rails.env.development? %> - \ No newline at end of file + diff --git a/app/views/orders/_order.html.erb b/app/views/orders/_order.html.erb index dc60779..7219fa9 100644 --- a/app/views/orders/_order.html.erb +++ b/app/views/orders/_order.html.erb @@ -1,8 +1,6 @@
  • - - <%= link_to order.user.name, order.user %> <%= order.products %> Posted <%= time_ago_in_words(order.created_at) %> ago. -
  • \ No newline at end of file + diff --git a/app/views/orders/new.html.erb b/app/views/orders/new.html.erb index 2cec404..840fe84 100644 --- a/app/views/orders/new.html.erb +++ b/app/views/orders/new.html.erb @@ -1,3 +1,17 @@ -

    Orders#new

    -

    Find me in app/views/orders/new.html.erb

    -

    In opbouw!

    + + diff --git a/app/views/shared/_order_form.html.erb b/app/views/orders/order.html.erb similarity index 60% rename from app/views/shared/_order_form.html.erb rename to app/views/orders/order.html.erb index 9873a5b..7f6047b 100644 --- a/app/views/shared/_order_form.html.erb +++ b/app/views/orders/order.html.erb @@ -1,7 +1,7 @@ -<%= form_for(@order) do |f| %> - <%= render 'shared/error_messages', object: f.object %> +<%= current_ordering_user.name %> +<%= form_for @order do |f| %>
    <%= f.text_area :products, placeholder: "Compose new order..." %>
    <%= f.submit "Order", class: "btn btn-primary" %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb deleted file mode 100644 index 71c995f..0000000 --- a/app/views/orders/show.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= @user.name %> - -<%= render 'shared/order_form' %> \ No newline at end of file diff --git a/app/views/products/create.html.erb b/app/views/products/create.html.erb deleted file mode 100644 index d546021..0000000 --- a/app/views/products/create.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

    Products#create

    -

    Find me in app/views/products/create.html.erb

    diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb deleted file mode 100644 index ce0e34c..0000000 --- a/app/views/products/edit.html.erb +++ /dev/null @@ -1,26 +0,0 @@ -

    Product edit

    - -
    -
    - <%= form_for(@product) do |f| %> - <%= render 'shared/error_messages', object: f.object %> - - <%= f.label :name %> - <%= f.text_field :name %> -
    - <%= f.label :purchase_price %> - <%= f.number_field :purchase_price %> -
    - <%= f.label :sale_price %> - <%= f.number_field :sale_price %> -
    - <%= f.label :image_path %> - <%= f.text_field :image_path %> - - - -
    - <%= f.submit "Update product", class: "btn btn-primary" %> - <% end %> -
    -
    \ No newline at end of file diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb deleted file mode 100644 index 26f9b7b..0000000 --- a/app/views/products/new.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -

    Product creation

    - -
    -
    - <%= form_for(@product) do |f| %> - <%= render 'shared/error_messages', object: f.object %> - <%= f.label :name %> - <%= f.text_field :name %> -
    - <%= f.label :purchase_price %> - <%= f.number_field :purchase_price %> -
    - <%= f.label :sale_price %> - <%= f.number_field :sale_price %> -
    - <%= f.label :image_path %> - <%= f.text_field :image_path %> - - - -
    - <%= f.submit "Create product", class: "btn btn-primary" %> - <% end %> -
    -
    \ No newline at end of file diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb deleted file mode 100644 index 54b113b..0000000 --- a/app/views/products/show.html.erb +++ /dev/null @@ -1,8 +0,0 @@ -

    Products#show

    -

    Find me in app/views/products/show.html.erb

    -name: <%= @product.name %>
    -verkoop prijs: <%= @product.sale_price %> EUR cent
    -aankoop prijs: <%= @product.purchase_price %> EUR cent
    - - -<%= link_to "Edit", edit_product_path(@product), class: "btn btn-lg btn-primary" %> \ No newline at end of file diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb deleted file mode 100644 index 095a8e9..0000000 --- a/app/views/sessions/new.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -

    Sessions#new

    -

    Find me in app/views/sessions/new.html.erb

    -

    Log in

    - -
    -
    - <%= form_for(:session, url: login_path) do |f| %> - - <%= f.label :name %> - <%= f.text_field :name, class: 'form-control' %> - - - - <%= f.submit "Log in", class: "btn btn-primary" %> - <% end %> - -

    New user? <%= link_to "Sign up now!", signup_path %>

    -
    -
    \ No newline at end of file diff --git a/app/views/shared/_error_messages.html.erb b/app/views/shared/_error_messages.html.erb deleted file mode 100644 index fad2204..0000000 --- a/app/views/shared/_error_messages.html.erb +++ /dev/null @@ -1,12 +0,0 @@ -<% if object.errors.any? %> -
    -
    - The form contains <%= pluralize(object.errors.count, "error") %>. -
    - -
    -<% end %> \ No newline at end of file diff --git a/app/views/shared/_feed.html.erb b/app/views/shared/_feed.html.erb deleted file mode 100644 index be8f344..0000000 --- a/app/views/shared/_feed.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -<% if @logs.any? %> -
      - <%= render @logs %> -
    - <%= will_paginate @logs %> -<% end %> \ No newline at end of file diff --git a/app/views/shared/_user_info.html.erb b/app/views/shared/_user_info.html.erb deleted file mode 100644 index 9e0282e..0000000 --- a/app/views/shared/_user_info.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -

    <%= current_user.name %>

    -<%= link_to "view my profile", current_user %> -<%= pluralize(current_user.orders.count, "order") %> \ No newline at end of file diff --git a/app/views/static_pages/_user.html.erb b/app/views/static_pages/_user.html.erb deleted file mode 100644 index 301050e..0000000 --- a/app/views/static_pages/_user.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -<% @users.each do |user| %> - -<% link = 'orders/' + user.id.to_s %> - > - <%= user.id %> - <%= user.name %> - <% user.marks.times do %> - <%= "|" %> - <% end %> - - - - -<%end%> \ No newline at end of file diff --git a/app/views/static_pages/help.html.erb b/app/views/static_pages/help.html.erb deleted file mode 100644 index 48523e8..0000000 --- a/app/views/static_pages/help.html.erb +++ /dev/null @@ -1 +0,0 @@ -

    HELP MIJ!!!! O.O

    \ No newline at end of file diff --git a/app/views/static_pages/home.html.erb b/app/views/static_pages/home.html.erb deleted file mode 100644 index c4e8594..0000000 --- a/app/views/static_pages/home.html.erb +++ /dev/null @@ -1,24 +0,0 @@ -

    StaticPages#home

    -

    Find me in app/views/static_pages/home.html.erb

    - -<% if logged_in? %> -
    - -
    -

    User logs

    - <%= render 'shared/feed' %> -
    -
    -<% else %> - -<%= link_to "Sign up now!", signup_path , class: "btn btn-lg btn-primary" %> - - -<% end %> \ No newline at end of file diff --git a/app/views/static_pages/overview.html.erb b/app/views/static_pages/overview.html.erb deleted file mode 100644 index d9450ae..0000000 --- a/app/views/static_pages/overview.html.erb +++ /dev/null @@ -1,26 +0,0 @@ -
    -
    - - - - - - - - - - - - <%= render "static_pages/user" %> - -
    #UsernameMarks
    -
    -
    - - \ No newline at end of file diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb deleted file mode 100644 index 9738e80..0000000 --- a/app/views/users/edit.html.erb +++ /dev/null @@ -1,23 +0,0 @@ -<% provide(:title, "Edit user") %> -

    Update your profile

    - -
    -
    - <%= form_for(@user) do |f| %> - <%= render 'shared/error_messages', object: f.object %> - - - <%= f.label :name %> - <%= f.text_field :name, class: 'form-control' %> - - <%= f.label :marks %> - <%= f.number_field :marks, class: 'form-control' %> - - - - <%= f.submit "Save changes", class: "btn btn-primary" %> - <% end %> - - -
    -
    \ No newline at end of file diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 0da4fea..df651ab 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,7 +1,5 @@

    All users

    -<%= will_paginate %> - - -<%= will_paginate %> \ No newline at end of file diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 0dba0eb..6fa72e3 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -3,16 +3,22 @@
    <%= form_for(@user) do |f| %> - <%= render 'shared/error_messages', object: f.object %> + <%= f.label :nickname %> + <%= f.text_field :nickname %> + <%= f.label :name %> <%= f.text_field :name %> -
    - <%= f.label :marks %> - <%= f.number_field :marks %> (tijdelijk) - -
    + <%= f.label :last_name %> + <%= f.text_field :last_name %> + + <%= f.label :password %> + <%= f.password_field :password %> + + <%= f.label :password_confirmation, "Confirmation" %> + <%= f.password_field :password_confirmation %> + <%= f.submit "Create my account", class: "btn btn-primary" %> <% end %>
    -
    \ No newline at end of file + diff --git a/app/views/users/order.html.erb b/app/views/users/order.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index b9cb844..084dc60 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,13 +1,22 @@
    +
    <% if @user.orders.any? %>

    Orders (<%= @user.orders.count %>)

    @@ -17,4 +26,4 @@ <%= will_paginate @orders %> <% end %>
    -
    \ No newline at end of file + diff --git a/bin/bundle b/bin/bundle old mode 100644 new mode 100755 index e3c2f62..66e9889 --- a/bin/bundle +++ b/bin/bundle @@ -1,3 +1,3 @@ -#!/usr/bin/env ruby.exe +#!/usr/bin/env ruby ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails old mode 100644 new mode 100755 index b9f8787..7feb6a3 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,8 @@ -#!/usr/bin/env ruby.exe +#!/usr/bin/env ruby +begin + load File.expand_path("../spring", __FILE__) +rescue LoadError +end APP_PATH = File.expand_path('../../config/application', __FILE__) require_relative '../config/boot' require 'rails/commands' diff --git a/bin/rake b/bin/rake old mode 100644 new mode 100755 index f6ed5a2..8017a02 --- a/bin/rake +++ b/bin/rake @@ -1,4 +1,8 @@ -#!/usr/bin/env ruby.exe +#!/usr/bin/env ruby +begin + load File.expand_path("../spring", __FILE__) +rescue LoadError +end require_relative '../config/boot' require 'rake' Rake.application.run diff --git a/bin/spring b/bin/spring new file mode 100755 index 0000000..7f24d96 --- /dev/null +++ b/bin/spring @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby + +# This file loads spring without using Bundler, in order to be fast +# It gets overwritten when you run the `spring binstub` command + +unless defined?(Spring) + require "rubygems" + require "bundler" + + if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m) + ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR) + ENV["GEM_HOME"] = "" + Gem.paths = ENV + + gem "spring", match[1] + require "spring/binstub" + end +end diff --git a/config/application.rb b/config/application.rb index 5a97282..92c2aa6 100644 --- a/config/application.rb +++ b/config/application.rb @@ -6,7 +6,7 @@ require 'rails/all' # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) -module Tab +module Tab002 class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index 404c21d..23f4f67 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,3 +1,3 @@ # Be sure to restart your server when you modify this file. -Rails.application.config.session_store :cookie_store, key: '_Tab_session' +Rails.application.config.session_store :cookie_store, key: '_Tab_0_0_2_session' diff --git a/config/routes.rb b/config/routes.rb index 2f491f1..7a55791 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,43 +1,17 @@ Rails.application.routes.draw do - - get 'products/new' - get 'products/show' - get 'products/create' - - get 'products/edit' - - get 'orders/show' - - root 'static_pages#home' - - get 'sessions/new' - - get 'users/new' - - - get 'help' => 'static_pages#help' - get 'static_pages/home' - get 'overview' => 'static_pages#overview' - get 'static_pages/overview' - - #order stuff - get 'order' => 'orders#new' - post 'order' => 'orders#create' - delete 'chaos' => 'orders#destroy' - - #account stuff - get 'signup' => 'users#new' - get 'login' => 'sessions#new' - post 'login' => 'sessions#create' - delete 'logout' => 'sessions#destroy' + root "users#index" resources :users - resources :orders - #product - resources :products + get 'overview' => 'orders#new' + post 'overview' => 'orders#create_session' + delete 'end_order' => 'orders#destroy' + + get 'order' => 'orders#order' + post 'orders' => 'orders#create' + # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/config/secrets.yml b/config/secrets.yml index 032e55e..90d7301 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -11,10 +11,10 @@ # if you're sharing your code publicly. development: - secret_key_base: 00f7233f9fe2e58e16b50f63f48e7160e9e99152b092004907130f4b7b8e3aac1b03f80b78b7666edf83ed84e20fd81890eec7e09ef3198cb47ee91bd08fa0ef + secret_key_base: 5d40610321e19e4f71ee2ba8af4f426fe15096c405da3800c6b33bed6779f2d11f55a0edc455974b19a01fd71f6cd508dba980305dbc55ff82521a2d12f891d8 test: - secret_key_base: c3861256e97380e1bcc1b78be6a5cc5b1b4bb3caacad11bb3b8de0d1a27d8df35d6fb6fe41f7c5cd41235c49d8ebd63a8aacf9925410a6714dc051b22edc2783 + secret_key_base: 961437e28e7d6055ffaad9cf1f8d614354f57f10cb2d7601c9d6ede72a03b9c9535ad9e63507e3eb31252c4895970a63117493408f2e9a46c7a0c4a5a7836b81 # Do not keep production secrets in the repository, # instead read values from the environment. diff --git a/db/migrate/20141110141100_create_products.rb b/db/migrate/20141110141100_create_products.rb deleted file mode 100644 index 7a4a09a..0000000 --- a/db/migrate/20141110141100_create_products.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateProducts < ActiveRecord::Migration - def change - create_table :products do |t| - t.string :name - t.integer :sale_price - t.integer :purchase_price - t.string :image_path - t.string :type - - t.timestamps - end - end -end diff --git a/db/migrate/20141106125617_create_users.rb b/db/migrate/20141123143707_create_users.rb similarity index 57% rename from db/migrate/20141106125617_create_users.rb rename to db/migrate/20141123143707_create_users.rb index 6ebc55f..c5b986a 100644 --- a/db/migrate/20141106125617_create_users.rb +++ b/db/migrate/20141123143707_create_users.rb @@ -2,8 +2,10 @@ class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :name - t.integer :marks - t.string :role + t.string :last_name + t.integer :balance + t.string :nickname + t.string :password_digest t.timestamps end diff --git a/db/migrate/20141109174952_create_orders.rb b/db/migrate/20141123151756_create_orders.rb similarity index 71% rename from db/migrate/20141109174952_create_orders.rb rename to db/migrate/20141123151756_create_orders.rb index 6d36487..f5088e3 100644 --- a/db/migrate/20141109174952_create_orders.rb +++ b/db/migrate/20141123151756_create_orders.rb @@ -1,10 +1,11 @@ class CreateOrders < ActiveRecord::Migration def change create_table :orders do |t| - t.text :products t.references :user, index: true + t.string :products + t.integer :cost - t.timestamps + t.timestamps null: false end add_index :orders, [:user_id, :created_at] end diff --git a/db/schema.rb b/db/schema.rb index 317ed73..1835fd4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,32 +11,25 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20141110141100) do +ActiveRecord::Schema.define(version: 20141123151756) do create_table "orders", force: true do |t| - t.text "products" t.integer "user_id" - t.datetime "created_at" - t.datetime "updated_at" + t.string "products" + t.integer "cost" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "orders", ["user_id", "created_at"], name: "index_orders_on_user_id_and_created_at" add_index "orders", ["user_id"], name: "index_orders_on_user_id" - create_table "products", force: true do |t| - t.string "name" - t.integer "sale_price" - t.integer "purchase_price" - t.string "image_path" - t.string "type" - t.datetime "created_at" - t.datetime "updated_at" - end - create_table "users", force: true do |t| t.string "name" - t.integer "marks" - t.string "role" + t.string "last_name" + t.integer "balance" + t.string "nickname" + t.string "password_digest" t.datetime "created_at" t.datetime "updated_at" end diff --git a/db/seeds.rb b/db/seeds.rb index 069e2f6..4edb1e8 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,19 +5,3 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) - - -User.create!(name: "Example User", marks: 5) - -99.times do |n| - name = Faker::Name.name - marks = n+1 - User.create!(name: name, - marks: marks) -end - -users = User.order(:created_at).take(6) -50.times do - products = Faker::Lorem.sentence(5) - users.each { |user| user.orders.create!(products: products) } -end \ No newline at end of file diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb index beda444..0afece1 100644 --- a/test/controllers/orders_controller_test.rb +++ b/test/controllers/orders_controller_test.rb @@ -1,9 +1,7 @@ require 'test_helper' class OrdersControllerTest < ActionController::TestCase - test "should get new" do - get :new - assert_response :success - end - + # test "the truth" do + # assert true + # end end diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb deleted file mode 100644 index fdd03f5..0000000 --- a/test/controllers/products_controller_test.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'test_helper' - -class ProductsControllerTest < ActionController::TestCase - test "should get new" do - get :new - assert_response :success - end - - test "should get show" do - get :show - assert_response :success - end - - test "should get create" do - get :create - assert_response :success - end - - test "should get edit" do - get :edit - assert_response :success - end - -end diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb deleted file mode 100644 index 75db968..0000000 --- a/test/controllers/sessions_controller_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'test_helper' - -class SessionsControllerTest < ActionController::TestCase - test "should get new" do - get :new - assert_response :success - end - -end diff --git a/test/controllers/static_pages_controller_test.rb b/test/controllers/static_pages_controller_test.rb deleted file mode 100644 index c160a49..0000000 --- a/test/controllers/static_pages_controller_test.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'test_helper' - -class StaticPagesControllerTest < ActionController::TestCase - test "should get home" do - get :home - assert_response :success - end - - test "should get overview" do - get :overview - assert_response :success - end - -end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 7d2d9b1..8833b41 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -6,4 +6,9 @@ class UsersControllerTest < ActionController::TestCase assert_response :success end + test "should get show" do + get :show + assert_response :success + end + end diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml index 1b4cdb8..8516b25 100644 --- a/test/fixtures/orders.yml +++ b/test/fixtures/orders.yml @@ -1,9 +1,11 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: - products: - user_id: + user: + products: MyString + cost: two: - products: - user_id: + user: + products: MyString + cost: diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml deleted file mode 100644 index e46cb4c..0000000 --- a/test/fixtures/products.yml +++ /dev/null @@ -1,11 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html - -one: - name: MyString - sale-price: 1 - purchase-price: 1 - -two: - name: MyString - sale-price: 1 - purchase-price: 1 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index d31e5ac..6ef07e8 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -2,10 +2,14 @@ one: name: MyString - marks: 1 - role: MyString + last_name: MyString + balance: 1 + nickname: MyString + password_digest: MyString two: name: MyString - marks: 1 - role: MyString + last_name: MyString + balance: 1 + nickname: MyString + password_digest: MyString diff --git a/test/helpers/products_helper_test.rb b/test/helpers/products_helper_test.rb deleted file mode 100644 index 0f5beab..0000000 --- a/test/helpers/products_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class ProductsHelperTest < ActionView::TestCase -end diff --git a/test/helpers/sessions_helper_test.rb b/test/helpers/sessions_helper_test.rb deleted file mode 100644 index 7d44e09..0000000 --- a/test/helpers/sessions_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class SessionsHelperTest < ActionView::TestCase -end diff --git a/test/helpers/static_pages_helper_test.rb b/test/helpers/static_pages_helper_test.rb deleted file mode 100644 index a1f06a2..0000000 --- a/test/helpers/static_pages_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class StaticPagesHelperTest < ActionView::TestCase -end diff --git a/test/models/product_test.rb b/test/models/product_test.rb deleted file mode 100644 index 211cdd0..0000000 --- a/test/models/product_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class ProductTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end