diff --git a/README.rdoc b/README.rdoc index dd4e97e..60fd490 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,28 +1,14 @@ -== README +== Tab -This README would normally document whatever steps are necessary to get the -application up and running. +Yes. We have to drink. But we also have to pay. This combines both. -Things you may want to cover: - -* Ruby version - -* System dependencies - -* Configuration - -* Database creation - -* Database initialization - -* How to run the test suite - -* Services (job queues, cache servers, search engines, etc.) - -* Deployment instructions - -* ... +* Ruby v2.0.5 +* rails v4.1.7 -Please feel free to use a different markup language if you do not plan to run -rake doc:app. += To do: + +- layout fixes +- user acces +- products JSON -> rails params !! +- product images diff --git a/app/assets/javascripts/products.js.coffee b/app/assets/javascripts/products.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/products.js.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/products.css.scss b/app/assets/stylesheets/products.css.scss new file mode 100644 index 0000000..bff386e --- /dev/null +++ b/app/assets/stylesheets/products.css.scss @@ -0,0 +1,3 @@ +// 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/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 1f1ee7d..630c7d5 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -15,13 +15,14 @@ class OrdersController < ApplicationController def order @order = current_ordering_user.orders.build + @products = Product.all end def create @order = current_ordering_user.orders.build(order_params) if @order.save - flash[:success] = "order created!" + #flash[:success] = "order created!" end_order redirect_to overview_path else diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000..5c99e89 --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,32 @@ +class ProductsController < ApplicationController + def new + @product = Product.new + end + + def create + @product = Product.new(params_products) + if @product.save + redirect_to @product + else + render "new" + end + end + + def show + @product = Product.find(params[:id]) + end + + def edit + end + + def delete + end + + private + + def params_products + params.require(:product).permit(:name, :purchase_price, :sale_price, + :img_path) + end + +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8db533a..354e835 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -23,8 +23,8 @@ class UsersController < ApplicationController private - def user_params - params.require(:user).permit(:name, :last_name, :password, - :password_confirmation, :nickname) - end + def user_params + params.require(:user).permit(:name, :last_name, :password, + :password_confirmation, :nickname) + end end diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb new file mode 100644 index 0000000..ab5c42b --- /dev/null +++ b/app/helpers/products_helper.rb @@ -0,0 +1,2 @@ +module ProductsHelper +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 0000000..077a819 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,2 @@ +class Product < ActiveRecord::Base +end diff --git a/app/views/orders/_order_button.html.erb b/app/views/orders/_order_button.html.erb new file mode 100644 index 0000000..7f7a5b4 --- /dev/null +++ b/app/views/orders/_order_button.html.erb @@ -0,0 +1,5 @@ + diff --git a/app/views/orders/new.html.erb b/app/views/orders/new.html.erb index 840fe84..f160ab0 100644 --- a/app/views/orders/new.html.erb +++ b/app/views/orders/new.html.erb @@ -1,17 +1,11 @@ - diff --git a/app/views/orders/order.html.erb b/app/views/orders/order.html.erb index 7f6047b..ae5a710 100644 --- a/app/views/orders/order.html.erb +++ b/app/views/orders/order.html.erb @@ -1,7 +1,89 @@ <%= current_ordering_user.name %> + +<% @products.each do |p| %> + <%#= render "orders/order_button" %> + + + + + +<% end %> + + + + + <%= form_for @order do |f| %>
- <%= f.text_area :products, placeholder: "Compose new order..." %> + <%= f.text_area :products , placeholder: "dit zou een hidden field moeten zijn met product JSON..." %>
- <%= f.submit "Order", class: "btn btn-primary" %> + <%#= hidden_field_tag "products", "return_products_string" %> + + + <%= f.submit "Order", class: "btn btn-primary " %> <% end %> + + +
+

+ Nothing ordered yet! +

+
+ + + + diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb new file mode 100644 index 0000000..279b066 --- /dev/null +++ b/app/views/products/edit.html.erb @@ -0,0 +1,2 @@ +

Products#edit

+

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

diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb new file mode 100644 index 0000000..b76165e --- /dev/null +++ b/app/views/products/new.html.erb @@ -0,0 +1,15 @@ +<%= form_for @product do |f| %> + <%= 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 :img_path %> + <%= f.text_field :img_path %> + + <%= f.submit "Create product", class: "btn btn-primary" %> +<% end %> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb new file mode 100644 index 0000000..cc14c8c --- /dev/null +++ b/app/views/products/show.html.erb @@ -0,0 +1,9 @@ + diff --git a/config/routes.rb b/config/routes.rb index 7a55791..a9ad3bb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,14 +1,20 @@ Rails.application.routes.draw do - root "users#index" resources :users + resources :products get 'overview' => 'orders#new' post 'overview' => 'orders#create_session' delete 'end_order' => 'orders#destroy' + #products + get 'products' => 'products#new' + post 'products' => 'products#create' + + + #orders get 'order' => 'orders#order' post 'orders' => 'orders#create' diff --git a/db/migrate/20141124091707_create_products.rb b/db/migrate/20141124091707_create_products.rb new file mode 100644 index 0000000..e1337ab --- /dev/null +++ b/db/migrate/20141124091707_create_products.rb @@ -0,0 +1,12 @@ +class CreateProducts < ActiveRecord::Migration + def change + create_table :products do |t| + t.string :name + t.integer :purchase_price + t.integer :sale_price + t.string :img_path + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 1835fd4..9484f1a 100644 --- 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: 20141123151756) do +ActiveRecord::Schema.define(version: 20141124091707) do create_table "orders", force: true do |t| t.integer "user_id" @@ -24,6 +24,15 @@ ActiveRecord::Schema.define(version: 20141123151756) do 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 "purchase_price" + t.integer "sale_price" + t.string "img_path" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "users", force: true do |t| t.string "name" t.string "last_name" diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb new file mode 100644 index 0000000..f802829 --- /dev/null +++ b/test/controllers/products_controller_test.rb @@ -0,0 +1,24 @@ +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 edit" do + get :edit + assert_response :success + end + + test "should get delete" do + get :delete + assert_response :success + end + +end diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml new file mode 100644 index 0000000..28ba2a5 --- /dev/null +++ b/test/fixtures/products.yml @@ -0,0 +1,13 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + purchase_price: 1 + sale_price: 1 + img_path: MyString + +two: + name: MyString + purchase_price: 1 + sale_price: 1 + img_path: MyString diff --git a/test/helpers/products_helper_test.rb b/test/helpers/products_helper_test.rb new file mode 100644 index 0000000..0f5beab --- /dev/null +++ b/test/helpers/products_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class ProductsHelperTest < ActionView::TestCase +end diff --git a/test/models/product_test.rb b/test/models/product_test.rb new file mode 100644 index 0000000..211cdd0 --- /dev/null +++ b/test/models/product_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ProductTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end