producten
This commit is contained in:
parent
3dd5873a55
commit
c62b064128
19 changed files with 167 additions and 3 deletions
3
app/assets/javascripts/products.js.coffee
Normal file
3
app/assets/javascripts/products.js.coffee
Normal 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/
|
3
app/assets/stylesheets/products.css.scss
Normal file
3
app/assets/stylesheets/products.css.scss
Normal 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/
|
|
@ -2,6 +2,7 @@ class OrdersController < ApplicationController
|
|||
before_action :logged_in_user, only: [:create, :destroy]
|
||||
|
||||
def new
|
||||
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
|
30
app/controllers/products_controller.rb
Normal file
30
app/controllers/products_controller.rb
Normal 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
|
2
app/helpers/products_helper.rb
Normal file
2
app/helpers/products_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module ProductsHelper
|
||||
end
|
11
app/models/product.rb
Normal file
11
app/models/product.rb
Normal 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
|
|
@ -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.
|
||||
|
|
2
app/views/products/create.html.erb
Normal file
2
app/views/products/create.html.erb
Normal file
|
@ -0,0 +1,2 @@
|
|||
<h1>Products#create</h1>
|
||||
<p>Find me in app/views/products/create.html.erb</p>
|
2
app/views/products/edit.html.erb
Normal file
2
app/views/products/edit.html.erb
Normal file
|
@ -0,0 +1,2 @@
|
|||
<h1>Products#edit</h1>
|
||||
<p>Find me in app/views/products/edit.html.erb</p>
|
25
app/views/products/new.html.erb
Normal file
25
app/views/products/new.html.erb
Normal 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>
|
5
app/views/products/show.html.erb
Normal file
5
app/views/products/show.html.erb
Normal 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>
|
|
@ -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 %>
|
||||
|
|
|
@ -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".
|
||||
|
|
13
db/migrate/20141110141100_create_products.rb
Normal file
13
db/migrate/20141110141100_create_products.rb
Normal 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
|
12
db/schema.rb
12
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: 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"
|
||||
|
|
24
test/controllers/products_controller_test.rb
Normal file
24
test/controllers/products_controller_test.rb
Normal 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
11
test/fixtures/products.yml
vendored
Normal 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
|
4
test/helpers/products_helper_test.rb
Normal file
4
test/helpers/products_helper_test.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ProductsHelperTest < ActionView::TestCase
|
||||
end
|
7
test/models/product_test.rb
Normal file
7
test/models/product_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ProductTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Loading…
Reference in a new issue