producten

This commit is contained in:
ohsab 2014-11-10 15:52:54 +01:00
parent 3dd5873a55
commit c62b064128
19 changed files with 167 additions and 3 deletions

View file

@ -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/

View file

@ -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/

View file

@ -2,6 +2,7 @@ class OrdersController < ApplicationController
before_action :logged_in_user, only: [:create, :destroy]
def new
end
def destroy

View file

@ -0,0 +1,30 @@
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
end
private
def product_params
params.require(:product).permit(:name, :sale_price, :purchase_price,
:image_path)
end
end

View file

@ -0,0 +1,2 @@
module ProductsHelper
end

11
app/models/product.rb Normal file
View file

@ -0,0 +1,11 @@
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

View file

@ -8,7 +8,7 @@ class User < ActiveRecord::Base
def init
self.marks ||= 0
self.role ||= "user"
end
end
def feed
# This is preliminary. See "Following users" for the full implementation.

View file

@ -0,0 +1,2 @@
<h1>Products#create</h1>
<p>Find me in app/views/products/create.html.erb</p>

View file

@ -0,0 +1,2 @@
<h1>Products#edit</h1>
<p>Find me in app/views/products/edit.html.erb</p>

View file

@ -0,0 +1,25 @@
<h1>Product creation</h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(@product) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.label :name %>
<%= f.text_field :name %>
</br>
<%= f.label :purchase_price %>
<%= f.number_field :purchase_price %>
</br>
<%= f.label :sale_price %>
<%= f.number_field :sale_price %>
</br>
<%= f.label :image_path %>
<%= f.text_field :image_path %>
</br>
<%= f.submit "Create product", class: "btn btn-primary" %>
<% end %>
</div>
</div>

View file

@ -0,0 +1,5 @@
<h1>Products#show</h1>
<p>Find me in app/views/products/show.html.erb</p>
name: <%= @product.name %></br>
verkoop prijs: <%= @product.sale_price %> EUR</br>
aankoop prijs: <%= @product.purchase_price %> EUR</br>

View file

@ -1,6 +1,7 @@
<% @users.each do |user| %>
<tr class="clickableRow" href= <%= "order"%> >
<% link = 'orders/' + user.id.to_s %>
<tr class="clickableRow" href= <%= link %> >
<td><%= user.id %></td>
<td><%= user.name %></td>
<td><% user.marks.times do %>

View file

@ -1,5 +1,13 @@
Rails.application.routes.draw do
get 'products/new'
get 'products/show'
get 'products/create'
get 'products/edit'
get 'orders/show'
root 'static_pages#home'
@ -30,6 +38,8 @@ Rails.application.routes.draw do
delete 'logout' => 'sessions#destroy'
resources :users
resources :orders
resources :products
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

View file

@ -0,0 +1,13 @@
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

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20141109174952) do
ActiveRecord::Schema.define(version: 20141110141100) do
create_table "orders", force: true do |t|
t.text "products"
@ -23,6 +23,16 @@ ActiveRecord::Schema.define(version: 20141109174952) 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 "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"

View file

@ -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 create" do
get :create
assert_response :success
end
test "should get edit" do
get :edit
assert_response :success
end
end

11
test/fixtures/products.yml vendored Normal file
View file

@ -0,0 +1,11 @@
# 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

View file

@ -0,0 +1,4 @@
require 'test_helper'
class ProductsHelperTest < ActionView::TestCase
end

View file

@ -0,0 +1,7 @@
require 'test_helper'
class ProductTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end