Commit ceb74a0c by Tran Hoang Viet

VietTH: Create new product with new attribute :stock

parent d95632a4
......@@ -18,6 +18,8 @@
color: blue;
}
}
}
.input-group.spinner{
.input-group-addon{
padding: 7px 12px;
}
......
......@@ -133,3 +133,7 @@ footer{
border-left: 0 !important;
border-right: 0 !important;
}
.text-left{
text-align: left !important;
}
\ No newline at end of file
class ProductsController < ApplicationController
before_action :set_product, only: [:show, :add_cart]
before_action :set_categories, only: [:new]
before_action :set_categories, only: [:new, :create]
before_action :add_breadcrumb_home
before_action :authenticate_user!, only: [:new, :create, :add_cart]
......@@ -48,7 +48,7 @@ class ProductsController < ApplicationController
end
def product_params
params.require(:product).permit(:title, :price, :category_id, :image)
params.require(:product).permit(:title, :price, :category_id, :image, :stock)
end
def cart_service
......
......@@ -12,6 +12,7 @@ class Product < ActiveRecord::Base
# validates
validates :title, presence: true, length: {maximum: 255}
validates :category, presence: true
validates :stock, presence: true, numericality: {greater_than: 0}
enum product_type: %i(system amazon)
......
......@@ -8,7 +8,24 @@
.form-group
= f.label :price, class: 'col-sm-2 control-label'
.col-sm-4
= f.text_field :price, class: 'form-control'
.customize-spinner.input-group.spinner{"data-trigger" => "spinner"}
= f.text_field :price, class: 'form-control text-left', data: {min: 0, step: 1}
.input-group-addon
%a.spin-up{"data-spin" => "up", href: "javascript:;"}
%i.fa.fa-sort-up
%a.spin-down{"data-spin" => "down", href: "javascript:;"}
%i.fa.fa-sort-down
.form-group
= f.label :stock,'Stock*', class: 'col-sm-2 control-label'
.col-sm-4
.customize-spinner.input-group.spinner{"data-trigger" => "spinner"}
= f.text_field :stock, class: 'form-control text-left', data: {min: 1, step: 1}
.input-group-addon
%a.spin-up{"data-spin" => "up", href: "javascript:;"}
%i.fa.fa-sort-up
%a.spin-down{"data-spin" => "down", href: "javascript:;"}
%i.fa.fa-sort-down
.form-group
= f.label :category, class: 'col-sm-2 control-label'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment