add stock to products and some clean up
This commit is contained in:
parent
49dc9201b6
commit
9e72274629
34 changed files with 123 additions and 114 deletions
|
@ -9,14 +9,18 @@ ready = ->
|
||||||
increment($(this), -1)
|
increment($(this), -1)
|
||||||
|
|
||||||
$('.btn-dec').prop("disabled", true)
|
$('.btn-dec').prop("disabled", true)
|
||||||
|
$('.btn-inc').each((index, button) ->
|
||||||
|
$(button).prop("disabled", $(button).closest('.form_row').find('.stock').val() == '0')
|
||||||
|
)
|
||||||
|
|
||||||
increment = (button, n) ->
|
increment = (button, n) ->
|
||||||
# Fix the counter
|
# Fix the counter
|
||||||
counter = $(button).closest('.form_row').find('.row_counter')
|
counter = $(button).closest('.form_row').find('.row_counter')
|
||||||
counter.val(parseInt(counter.val()) + n)
|
counter.val(parseInt(counter.val()) + n)
|
||||||
|
|
||||||
# Enable or disable the dec button
|
# Enable or disable the buttons
|
||||||
counter.parent().find('.btn-dec').prop("disabled", counter.val() == '0');
|
counter.parent().find('.btn-dec').prop('disabled', counter.val() == '0');
|
||||||
|
counter.parent().find('.btn-inc').prop('disabled', counter.val() == counter.parent().find('.stock').val());
|
||||||
|
|
||||||
# Update the price
|
# Update the price
|
||||||
oldVal = parseFloat($('#order_total_price').val())
|
oldVal = parseFloat($('#order_total_price').val())
|
||||||
|
|
|
@ -5,8 +5,7 @@ class ApplicationController < ActionController::Base
|
||||||
before_action :configure_permitted_parameters, if: :devise_controller?
|
before_action :configure_permitted_parameters, if: :devise_controller?
|
||||||
|
|
||||||
rescue_from CanCan::AccessDenied do |exception|
|
rescue_from CanCan::AccessDenied do |exception|
|
||||||
flash[:error] = exception.message
|
redirect_to root_path, flash: { error: exception.message }
|
||||||
redirect_to root_path
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_sign_in_path_for(resource)
|
def after_sign_in_path_for(resource)
|
||||||
|
@ -14,7 +13,7 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_sign_up_path_for(resource)
|
def after_sign_up_path_for(resource)
|
||||||
new_user_session_path
|
root_path
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
@ -24,9 +23,9 @@ class ApplicationController < ActionController::Base
|
||||||
:nickname, :name, :last_name, :password, :password_confirmation,
|
:nickname, :name, :last_name, :password, :password_confirmation,
|
||||||
:current_password, :avatar
|
:current_password, :avatar
|
||||||
) }
|
) }
|
||||||
|
|
||||||
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(
|
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(
|
||||||
:password, :password_confirmation, :current_password, :avatar
|
:password, :password_confirmation, :current_password, :avatar
|
||||||
) }
|
) }
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,8 +19,9 @@ class OrdersController < ApplicationController
|
||||||
@order = @user.orders.build(order_params)
|
@order = @user.orders.build(order_params)
|
||||||
@products = Product.all
|
@products = Product.all
|
||||||
@order_products = @order.order_products
|
@order_products = @order.order_products
|
||||||
|
|
||||||
if @order.save
|
if @order.save
|
||||||
flash[:success] = order_to_sentence(@order) + " ordered. Enjoy it!"
|
flash[:success] = "#{@order.to_sentence} ordered. Enjoy it!"
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
else
|
else
|
||||||
render 'new'
|
render 'new'
|
||||||
|
@ -33,13 +34,13 @@ class OrdersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def quickpay
|
def quickpay
|
||||||
@user = User.find(params[:user_id])
|
user = User.find(params[:user_id])
|
||||||
order = @user.orders.build
|
order = user.orders.build
|
||||||
order.products << @user.dagschotel
|
order.products << user.dagschotel
|
||||||
if order.save
|
if order.save
|
||||||
flash[:success] = "Quick pay succeeded"
|
flash[:success] = "Quick pay succeeded"
|
||||||
else
|
else
|
||||||
flash[:error] = "Quick pay went wrong ... Sorry!"
|
flash[:error] = order.errors.full_messages.first
|
||||||
end
|
end
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,13 +36,13 @@ class ProductsController < ApplicationController
|
||||||
def destroy
|
def destroy
|
||||||
Product.find(params[:id]).destroy
|
Product.find(params[:id]).destroy
|
||||||
flash[:success] = "Succesfully removed product"
|
flash[:success] = "Succesfully removed product"
|
||||||
redirect_to products_path
|
redirect_to action: :index
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def product_params
|
def product_params
|
||||||
params.require(:product).permit(:name, :price, :avatar, :category)
|
params.require(:product).permit(:name, :price, :avatar, :category, :stock)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class UsersController < ApplicationController
|
class UsersController < ApplicationController
|
||||||
load_and_authorize_resource only: [:destroy]
|
load_and_authorize_resource
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@user = User.find_by_id(params[:id]) || current_user
|
@user = User.find_by_id(params[:id]) || current_user
|
||||||
|
@ -15,7 +15,7 @@ class UsersController < ApplicationController
|
||||||
def destroy
|
def destroy
|
||||||
User.find(params[:id]).destroy
|
User.find(params[:id]).destroy
|
||||||
flash[:success] = "Succesfully removed user"
|
flash[:success] = "Succesfully removed user"
|
||||||
redirect_to users_path
|
redirect_to action: :index
|
||||||
end
|
end
|
||||||
|
|
||||||
def dagschotel
|
def dagschotel
|
||||||
|
|
|
@ -13,11 +13,6 @@ module ApplicationHelper
|
||||||
"€#{number_with_precision f, precision: 2}"
|
"€#{number_with_precision f, precision: 2}"
|
||||||
end
|
end
|
||||||
|
|
||||||
#tijdelijk voor layout
|
|
||||||
def koelkast(status)
|
|
||||||
@koelkast ||= status
|
|
||||||
end
|
|
||||||
|
|
||||||
# Form helpers
|
# Form helpers
|
||||||
def form_errors(object)
|
def form_errors(object)
|
||||||
render partial: "form_errors", locals: {object: object}
|
render partial: "form_errors", locals: {object: object}
|
||||||
|
|
|
@ -1,9 +1,2 @@
|
||||||
module OrdersHelper
|
module OrdersHelper
|
||||||
include ActionView::Helpers::TextHelper
|
|
||||||
|
|
||||||
def order_to_sentence(order)
|
|
||||||
order.order_products.map {
|
|
||||||
|op| pluralize(op.count, op.product.name)
|
|
||||||
}.to_sentence
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,8 +10,10 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
class Order < ActiveRecord::Base
|
class Order < ActiveRecord::Base
|
||||||
|
include ActionView::Helpers::TextHelper
|
||||||
|
|
||||||
after_initialize { self.total_price = 0 }
|
after_initialize { self.total_price = 0 }
|
||||||
after_create :pay_price
|
after_create { self.user.pay(price) }
|
||||||
|
|
||||||
belongs_to :user, counter_cache: true
|
belongs_to :user, counter_cache: true
|
||||||
has_many :order_products
|
has_many :order_products
|
||||||
|
@ -20,21 +22,17 @@ class Order < ActiveRecord::Base
|
||||||
attr_accessor :total_price
|
attr_accessor :total_price
|
||||||
|
|
||||||
validates :user, presence: true
|
validates :user, presence: true
|
||||||
validates :order_products, presence: true
|
validates :order_products, presence: true, in_stock: true
|
||||||
|
|
||||||
accepts_nested_attributes_for :order_products, reject_if: proc { |op| op[:count].to_i <= 0 }
|
accepts_nested_attributes_for :order_products, reject_if: proc { |op| op[:count].to_i <= 0 }
|
||||||
|
|
||||||
def price
|
def price
|
||||||
price = 0
|
self.order_products.map{ |op| op.count * op.product.price }.sum
|
||||||
order_products.each do |op|
|
|
||||||
price += op.count * op.product.read_attribute(:price)
|
|
||||||
end
|
|
||||||
price
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def to_sentence
|
||||||
|
self.order_products.map {
|
||||||
def pay_price
|
|op| pluralize(op.count, op.product.name)
|
||||||
user.pay(price)
|
}.to_sentence
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
class OrderProduct < ActiveRecord::Base
|
class OrderProduct < ActiveRecord::Base
|
||||||
|
after_create :remove_from_stock
|
||||||
|
|
||||||
belongs_to :order
|
belongs_to :order
|
||||||
belongs_to :product
|
belongs_to :product
|
||||||
|
|
||||||
|
@ -16,4 +18,11 @@ class OrderProduct < ActiveRecord::Base
|
||||||
validates :count, numericality: { greater_than_or_equal_to: 0 }
|
validates :count, numericality: { greater_than_or_equal_to: 0 }
|
||||||
|
|
||||||
accepts_nested_attributes_for :product
|
accepts_nested_attributes_for :product
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def remove_from_stock
|
||||||
|
product.stock -= self.count
|
||||||
|
product.save
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
# avatar_file_size :integer
|
# avatar_file_size :integer
|
||||||
# avatar_updated_at :datetime
|
# avatar_updated_at :datetime
|
||||||
# category :integer default(0)
|
# category :integer default(0)
|
||||||
|
# stock :integer default(0)
|
||||||
#
|
#
|
||||||
|
|
||||||
class Product < ActiveRecord::Base
|
class Product < ActiveRecord::Base
|
||||||
|
@ -22,6 +23,7 @@ class Product < ActiveRecord::Base
|
||||||
|
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
validates :price, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
validates :price, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
||||||
|
validates :stock, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
||||||
validates_attachment :avatar, presence: true, content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
|
validates_attachment :avatar, presence: true, content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
|
||||||
|
|
||||||
def price
|
def price
|
||||||
|
|
|
@ -23,12 +23,13 @@
|
||||||
# avatar_file_size :integer
|
# avatar_file_size :integer
|
||||||
# avatar_updated_at :datetime
|
# avatar_updated_at :datetime
|
||||||
# orders_count :integer default(0)
|
# orders_count :integer default(0)
|
||||||
|
# koelkast :boolean default(FALSE)
|
||||||
#
|
#
|
||||||
|
|
||||||
class User < ActiveRecord::Base
|
class User < ActiveRecord::Base
|
||||||
devise :database_authenticatable, :registerable,
|
devise :database_authenticatable, :registerable, :rememberable, :trackable
|
||||||
:rememberable, :trackable
|
has_attached_file :avatar, styles: { medium: "100x100>" }, default_style: :medium,
|
||||||
has_attached_file :avatar, styles: { medium: "100x100>" }, default_style: :medium, default_url: "http://babeholder.pixoil.com/img/70/70"
|
default_url: "http://babeholder.pixoil.com/img/70/70"
|
||||||
|
|
||||||
has_many :orders, -> { includes :products }
|
has_many :orders, -> { includes :products }
|
||||||
has_many :products, through: :orders
|
has_many :products, through: :orders
|
||||||
|
|
7
app/validators/in_stock_validator.rb
Normal file
7
app/validators/in_stock_validator.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
class InStockValidator < ActiveModel::Validator
|
||||||
|
def validate(record)
|
||||||
|
record.order_products.each do |op|
|
||||||
|
record.errors[op.product.name] = "is not in stock anymore" if op.count > op.product.stock
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,4 +1,5 @@
|
||||||
<h2>Edit <%= resource_name.to_s.humanize %></h2>
|
<h2>Edit <%= resource_name.to_s.humanize %></h2>
|
||||||
|
<%= render 'flash' %>
|
||||||
|
|
||||||
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
|
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
|
||||||
<%= devise_error_messages! %>
|
<%= devise_error_messages! %>
|
||||||
|
|
|
@ -15,11 +15,6 @@
|
||||||
</div>
|
</div>
|
||||||
<%= render "layouts/footer" %>
|
<%= render "layouts/footer" %>
|
||||||
<%= debug(params) if Rails.env.development? %>
|
<%= debug(params) if Rails.env.development? %>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
<div class="col-md-3 form_products">
|
|
||||||
<div class="thumbnail ">
|
|
||||||
<div class="form_row center">
|
|
||||||
<%= image_tag f.object.product.avatar %>
|
|
||||||
<div class="caption">
|
|
||||||
<h3><%= f.object.product.name %> - <%= content_tag :span, euro(f.object.product.price), class: "price" %></h3>
|
|
||||||
<p>
|
|
||||||
<div class="input-group">
|
|
||||||
<%= render 'btn_dec', id: f.object.product_id %>
|
|
||||||
<%= f.text_field :count, class: 'form-control row_counter', value: 0 %>
|
|
||||||
<%= f.hidden_field :price, value: f.object.product.price, class: :price %>
|
|
||||||
<%= render 'btn_inc', id: f.object.product_id %>
|
|
||||||
<%= f.hidden_field :product_id %>
|
|
||||||
</div>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
20
app/views/order_products/_order_product.html.erb
Normal file
20
app/views/order_products/_order_product.html.erb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<div class="col-md-3 form_products">
|
||||||
|
<div class="thumbnail ">
|
||||||
|
<div class="form_row center">
|
||||||
|
<%= image_tag product.avatar %>
|
||||||
|
<div class="caption">
|
||||||
|
<h3><%= product.name %> - <%= content_tag :span, euro(product.price), class: "price" %></h3>
|
||||||
|
<p>
|
||||||
|
<div class="input-group">
|
||||||
|
<%= render 'btn_dec', id: product.id %>
|
||||||
|
<%= f.text_field :count, class: 'form-control row_counter', value: 0 %>
|
||||||
|
<%= f.hidden_field :price, value: product.price, class: :price %>
|
||||||
|
<%= f.hidden_field :stock, value: product.stock, class: :stock %>
|
||||||
|
<%= render 'btn_inc', id: product.id %>
|
||||||
|
<%= f.hidden_field :product_id %>
|
||||||
|
</div>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -1,8 +1,10 @@
|
||||||
<%= f.label :total_price %>
|
<div class="col-md-3 form_total">
|
||||||
<div class="input-group">
|
<%= f.label :total_price %>
|
||||||
<span class="input-group-addon">€</span>
|
<div class="input-group">
|
||||||
<%= f.number_field :total_price, step: :any, class: 'form-control input-lg' %>
|
<span class="input-group-addon">€</span>
|
||||||
<span class="input-group-btn">
|
<%= f.number_field :total_price, step: :any, class: 'form-control input-lg' %>
|
||||||
<%= f.submit "Order!", class: "btn btn-primary input-lg" %>
|
<span class="input-group-btn">
|
||||||
</span>
|
<%= f.submit "Order!", class: "btn btn-primary input-lg" %>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,6 +1,2 @@
|
||||||
<%= order.created_at %>
|
<%= order.created_at %>
|
||||||
<p>
|
<%= simple_format(products.map { |p| pluralize(p.count, p.name) }.to_sentence) %>
|
||||||
<% products.each do |product| %>
|
|
||||||
<%= pluralize(product.count, product.name) %>
|
|
||||||
<% end %>
|
|
||||||
</p>
|
|
||||||
|
|
6
app/views/orders/_overview.html.erb
Normal file
6
app/views/orders/_overview.html.erb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<div class="col-md-6">
|
||||||
|
<h3 class="center" >sort by name</h3>
|
||||||
|
<% users.each do |user| %>
|
||||||
|
<%= render 'users/new_order', user: user %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
|
@ -1,9 +0,0 @@
|
||||||
<% users.each do |user| %>
|
|
||||||
<div class="thumbnail overview">
|
|
||||||
<%= link_to image_tag(user.dagschotel.avatar, class: "img-circle dagschotel"), user_quickpay_path(user) unless user.dagschotel.nil? %>
|
|
||||||
<%= link_to image_tag(user.avatar , class: "img-circle avatar"), new_user_order_path(user) %>
|
|
||||||
|
|
||||||
<%= link_to user.name , new_user_order_path(user), class: "btn btn-info",
|
|
||||||
style: get_color_style(user) %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
|
@ -6,13 +6,10 @@
|
||||||
|
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<%= f.fields_for :order_products do |op_field| %>
|
<%= f.fields_for :order_products do |op_field| %>
|
||||||
<%= render 'order_products/form_row', f: op_field %>
|
<%= render op_field.object, f: op_field, product: op_field.object.product %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-3 form_total">
|
<%= render 'order_products/total_price', f: f %>
|
||||||
<%= render 'order_products/total_price', f: f %>
|
<% end %>
|
||||||
</div>
|
|
||||||
|
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,11 +1,4 @@
|
||||||
<%= render partial: 'flash' %>
|
<%= render partial: 'flash' %>
|
||||||
|
|
||||||
<div class="col-md-6">
|
<%= render 'overview', users: @users_by_name %>
|
||||||
<h3 class="center" >sort by name</h3>
|
<%= render 'overview', users: @users_by_order %>
|
||||||
<%= render 'orders/user_list', users: @users_by_name %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-md-6">
|
|
||||||
<h3 class="center" >sort by order</h3>
|
|
||||||
<%= render 'orders/user_list', users: @users_by_order %>
|
|
||||||
</div>
|
|
||||||
|
|
|
@ -1,3 +1 @@
|
||||||
<p>
|
<%= simple_format(pluralize(category.count, category.category)) %>
|
||||||
<%= pluralize(category.count, category.category) %>
|
|
||||||
</p>
|
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
|
|
||||||
<%= form_collection_select f, :category, Product.categories.keys, :to_s, :titlecase %>
|
<%= form_collection_select f, :category, Product.categories.keys, :to_s, :titlecase %>
|
||||||
|
|
||||||
|
<%= f.label :stock %>
|
||||||
|
<%= f.number_field :stock, class: 'form-control form-field' %>
|
||||||
|
|
||||||
<%= f.label :avatar %>
|
<%= f.label :avatar %>
|
||||||
<%= f.file_field :avatar , class: "form-field" %>
|
<%= f.file_field :avatar , class: "form-field" %>
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,12 @@
|
||||||
<%= image_tag product.avatar %>
|
<%= image_tag product.avatar %>
|
||||||
<div class="caption">
|
<div class="caption">
|
||||||
<h3><%= product.name %> - <%= euro(product.price) %></h3>
|
<h3><%= product.name %> - <%= euro(product.price) %></h3>
|
||||||
<p>
|
<% if current_user.admin? %>
|
||||||
<%= link_to "Edit", edit_product_path(product), class: "btn btn-default" %>
|
<p>
|
||||||
<%= link_to "Delete", product_path(product), method: :delete, class: "btn btn-danger", data: {confirm: 'Are you sure?'} %>
|
<%= link_to "Edit", edit_product_path(product), class: "btn btn-default" %>
|
||||||
</p>
|
<%= link_to "Delete", product_path(product), method: :delete, class: "btn btn-danger", data: {confirm: 'Are you sure?'} %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,3 +1 @@
|
||||||
<p>
|
<%= simple_format(pluralize(product.count, product.name)) %>
|
||||||
<%= pluralize(product.count, product.name) %>
|
|
||||||
</p>
|
|
||||||
|
|
7
app/views/users/_new_order.html.erb
Normal file
7
app/views/users/_new_order.html.erb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<div class="thumbnail overview">
|
||||||
|
<%= link_to image_tag(user.dagschotel.avatar, class: "img-circle dagschotel"), user_quickpay_path(user) unless user.dagschotel.nil? %>
|
||||||
|
<%= link_to image_tag(user.avatar , class: "img-circle avatar"), new_user_order_path(user) %>
|
||||||
|
|
||||||
|
<%= link_to user.name , new_user_order_path(user), class: "btn btn-info",
|
||||||
|
style: get_color_style(user) %>
|
||||||
|
</div>
|
|
@ -1,6 +1,6 @@
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="thumbnail monopoly">
|
<div class="thumbnail monopoly">
|
||||||
<h3 class="header" style="background-color: #<%=get_color(user)%>;" ><%= user.full_name %></h3>
|
<h3 class="header" style="background-color: #<%= get_color(user)%>;" ><%= user.full_name %></h3>
|
||||||
<div class="caption">
|
<div class="caption">
|
||||||
<%= image_tag(user.avatar , class: "img-circle avatar") %>
|
<%= image_tag(user.avatar , class: "img-circle avatar") %>
|
||||||
<p><strong>Name:</strong> <%= user.name %></p>
|
<p><strong>Name:</strong> <%= user.name %></p>
|
||||||
|
|
5
db/migrate/20150113155744_add_stock_to_products.rb
Normal file
5
db/migrate/20150113155744_add_stock_to_products.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddStockToProducts < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :products, :stock, :integer, default: 0
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20141217063222) do
|
ActiveRecord::Schema.define(version: 20150113155744) do
|
||||||
|
|
||||||
create_table "order_products", force: true do |t|
|
create_table "order_products", force: true do |t|
|
||||||
t.integer "order_id"
|
t.integer "order_id"
|
||||||
|
@ -39,6 +39,7 @@ ActiveRecord::Schema.define(version: 20141217063222) do
|
||||||
t.integer "avatar_file_size"
|
t.integer "avatar_file_size"
|
||||||
t.datetime "avatar_updated_at"
|
t.datetime "avatar_updated_at"
|
||||||
t.integer "category", default: 0
|
t.integer "category", default: 0
|
||||||
|
t.integer "stock", default: 0
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "users", force: true do |t|
|
create_table "users", force: true do |t|
|
||||||
|
|
1
test/fixtures/products.yml
vendored
1
test/fixtures/products.yml
vendored
|
@ -12,6 +12,7 @@
|
||||||
# avatar_file_size :integer
|
# avatar_file_size :integer
|
||||||
# avatar_updated_at :datetime
|
# avatar_updated_at :datetime
|
||||||
# category :integer default(0)
|
# category :integer default(0)
|
||||||
|
# stock :integer default(0)
|
||||||
#
|
#
|
||||||
|
|
||||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
1
test/fixtures/users.yml
vendored
1
test/fixtures/users.yml
vendored
|
@ -23,6 +23,7 @@
|
||||||
# avatar_file_size :integer
|
# avatar_file_size :integer
|
||||||
# avatar_updated_at :datetime
|
# avatar_updated_at :datetime
|
||||||
# orders_count :integer default(0)
|
# orders_count :integer default(0)
|
||||||
|
# koelkast :boolean default(FALSE)
|
||||||
#
|
#
|
||||||
|
|
||||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
# avatar_file_size :integer
|
# avatar_file_size :integer
|
||||||
# avatar_updated_at :datetime
|
# avatar_updated_at :datetime
|
||||||
# category :integer default(0)
|
# category :integer default(0)
|
||||||
|
# stock :integer default(0)
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
# avatar_file_size :integer
|
# avatar_file_size :integer
|
||||||
# avatar_updated_at :datetime
|
# avatar_updated_at :datetime
|
||||||
# orders_count :integer default(0)
|
# orders_count :integer default(0)
|
||||||
|
# koelkast :boolean default(FALSE)
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
Loading…
Reference in a new issue