Commit 8912f75e by Nguyen Quoc Kien

Fix code

parent 9d557a5d
......@@ -6,17 +6,11 @@ class CartProductsController < ApplicationController
product = Product.find(params[:product_id])
if check_quantity?
add_product_to_cart(product.id.to_i, params[:quantity].to_i )
respond_to do |format|
format.html { redirect_to cart_path(id: @user_id),
notice: 'Products add to cart' }
format.json { head :no_content }
end
redirect_to cart_path(id: @user_id)
flash[:success] = 'Products add to cart'
else
respond_to do |format|
format.html { redirect_to cart_path(id: @user_id),
notice: 'Errors: Quantity' }
format.json { head :no_content }
end
redirect_to cart_path(id: @user_id)
flash[:success] = 'Errors: Quantity'
end
end
......@@ -44,9 +38,11 @@ class CartProductsController < ApplicationController
end
def check_quantity?
if ( params[:quantity].to_i && params[:quantity].to_i > 0 )
if params[:quantity].to_i > 0
return true
else false
else
return false
end
end
end
class CartsController < ApplicationController
#before_action :find_card, only: [ :create ]
def update
end
def new
@cart = Cart.new
end
def create
total = 0
@cart = Cart.new(cart_params)
@cart.save
if current_user
......@@ -20,7 +14,6 @@ class CartsController < ApplicationController
@cart.update(user_id: "", status: "Checkout")
user_id = 'guess'
end
if @cart.save
session[user_id].each do |key, value|
@product = Product.find(key)
......@@ -60,10 +53,6 @@ class CartsController < ApplicationController
params.require(:cart).permit(:full_name, :email, :address, :phone)
end
def find_card
@cart = Cart.find(params[:id])
end
def update_info_user
if user_signed_in?
user = User.find(current_user.id)
......
......@@ -6,14 +6,10 @@ class ProductsController < ApplicationController
@categories = Category.all
end
# GET /products/:id
def show
@categories = Category.all
end
def new
end
private
def find_product
......
class StaticPagesController < ApplicationController
def home
end
def help
end
def about
end
end
......@@ -19,8 +19,4 @@ class Cart < ActiveRecord::Base
def downcase_email
self.email = email.downcase
end
def check_valid
end
end
......@@ -7,8 +7,4 @@ class CartProduct < ActiveRecord::Base
validates :number, presence: true, format: { with: VALID_NUMBER_REGEX }
validates :price, presence: true, format: { with: VALID_NUMBER_REGEX }
def total_price
product.price * number
end
end
......@@ -8,11 +8,8 @@ class User < ActiveRecord::Base
:rememberable, :trackable, :validatable,
:authentication_keys => [:login]
VALID_PHONE_REGEX = /\d[0-9]\)*\z/
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :phone, length: { maximum: 12 },
format: { with: VALID_PHONE_REGEX }
validates :username, :presence => true, length: { maximum: 50 }, :uniqueness => { :case_sensitive => false }
validates :email, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX },
......
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