Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
venshop
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Nguyen Quoc Kien
venshop
Commits
8912f75e
Commit
8912f75e
authored
Jul 31, 2015
by
Nguyen Quoc Kien
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix code
parent
9d557a5d
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
8 additions
and
48 deletions
+8
-48
app/controllers/cart_products_controller.rb
+8
-12
app/controllers/carts_controller.rb
+0
-11
app/controllers/products_controller.rb
+0
-4
app/controllers/static_pages_controller.rb
+0
-10
app/models/cart.rb
+0
-4
app/models/cart_product.rb
+0
-4
app/models/user.rb
+0
-3
app/views/products/show.html.erb
+0
-0
No files found.
app/controllers/cart_products_controller.rb
View file @
8912f75e
...
@@ -6,17 +6,11 @@ class CartProductsController < ApplicationController
...
@@ -6,17 +6,11 @@ class CartProductsController < ApplicationController
product
=
Product
.
find
(
params
[
:product_id
])
product
=
Product
.
find
(
params
[
:product_id
])
if
check_quantity?
if
check_quantity?
add_product_to_cart
(
product
.
id
.
to_i
,
params
[
:quantity
].
to_i
)
add_product_to_cart
(
product
.
id
.
to_i
,
params
[
:quantity
].
to_i
)
respond_to
do
|
format
|
redirect_to
cart_path
(
id:
@user_id
)
format
.
html
{
redirect_to
cart_path
(
id:
@user_id
),
flash
[
:success
]
=
'Products add to cart'
notice:
'Products add to cart'
}
format
.
json
{
head
:no_content
}
end
else
else
respond_to
do
|
format
|
redirect_to
cart_path
(
id:
@user_id
)
format
.
html
{
redirect_to
cart_path
(
id:
@user_id
),
flash
[
:success
]
=
'Errors: Quantity'
notice:
'Errors: Quantity'
}
format
.
json
{
head
:no_content
}
end
end
end
end
end
...
@@ -44,9 +38,11 @@ class CartProductsController < ApplicationController
...
@@ -44,9 +38,11 @@ class CartProductsController < ApplicationController
end
end
def
check_quantity?
def
check_quantity?
if
(
params
[
:quantity
].
to_i
&&
params
[
:quantity
].
to_i
>
0
)
if
params
[
:quantity
].
to_i
>
0
return
true
return
true
else
false
else
return
false
end
end
end
end
end
end
app/controllers/carts_controller.rb
View file @
8912f75e
class
CartsController
<
ApplicationController
class
CartsController
<
ApplicationController
#before_action :find_card, only: [ :create ]
def
update
end
def
new
def
new
@cart
=
Cart
.
new
@cart
=
Cart
.
new
end
end
def
create
def
create
total
=
0
total
=
0
@cart
=
Cart
.
new
(
cart_params
)
@cart
=
Cart
.
new
(
cart_params
)
@cart
.
save
@cart
.
save
if
current_user
if
current_user
...
@@ -20,7 +14,6 @@ class CartsController < ApplicationController
...
@@ -20,7 +14,6 @@ class CartsController < ApplicationController
@cart
.
update
(
user_id:
""
,
status:
"Checkout"
)
@cart
.
update
(
user_id:
""
,
status:
"Checkout"
)
user_id
=
'guess'
user_id
=
'guess'
end
end
if
@cart
.
save
if
@cart
.
save
session
[
user_id
].
each
do
|
key
,
value
|
session
[
user_id
].
each
do
|
key
,
value
|
@product
=
Product
.
find
(
key
)
@product
=
Product
.
find
(
key
)
...
@@ -60,10 +53,6 @@ class CartsController < ApplicationController
...
@@ -60,10 +53,6 @@ class CartsController < ApplicationController
params
.
require
(
:cart
).
permit
(
:full_name
,
:email
,
:address
,
:phone
)
params
.
require
(
:cart
).
permit
(
:full_name
,
:email
,
:address
,
:phone
)
end
end
def
find_card
@cart
=
Cart
.
find
(
params
[
:id
])
end
def
update_info_user
def
update_info_user
if
user_signed_in?
if
user_signed_in?
user
=
User
.
find
(
current_user
.
id
)
user
=
User
.
find
(
current_user
.
id
)
...
...
app/controllers/products_controller.rb
View file @
8912f75e
...
@@ -6,14 +6,10 @@ class ProductsController < ApplicationController
...
@@ -6,14 +6,10 @@ class ProductsController < ApplicationController
@categories
=
Category
.
all
@categories
=
Category
.
all
end
end
# GET /products/:id
def
show
def
show
@categories
=
Category
.
all
@categories
=
Category
.
all
end
end
def
new
end
private
private
def
find_product
def
find_product
...
...
app/controllers/static_pages_controller.rb
View file @
8912f75e
class
StaticPagesController
<
ApplicationController
class
StaticPagesController
<
ApplicationController
def
home
end
def
help
end
def
about
end
end
end
app/models/cart.rb
View file @
8912f75e
...
@@ -19,8 +19,4 @@ class Cart < ActiveRecord::Base
...
@@ -19,8 +19,4 @@ class Cart < ActiveRecord::Base
def
downcase_email
def
downcase_email
self
.
email
=
email
.
downcase
self
.
email
=
email
.
downcase
end
end
def
check_valid
end
end
end
app/models/cart_product.rb
View file @
8912f75e
...
@@ -7,8 +7,4 @@ class CartProduct < ActiveRecord::Base
...
@@ -7,8 +7,4 @@ class CartProduct < ActiveRecord::Base
validates
:number
,
presence:
true
,
format:
{
with:
VALID_NUMBER_REGEX
}
validates
:number
,
presence:
true
,
format:
{
with:
VALID_NUMBER_REGEX
}
validates
:price
,
presence:
true
,
format:
{
with:
VALID_NUMBER_REGEX
}
validates
:price
,
presence:
true
,
format:
{
with:
VALID_NUMBER_REGEX
}
def
total_price
product
.
price
*
number
end
end
end
app/models/user.rb
View file @
8912f75e
...
@@ -8,11 +8,8 @@ class User < ActiveRecord::Base
...
@@ -8,11 +8,8 @@ class User < ActiveRecord::Base
:rememberable
,
:trackable
,
:validatable
,
:rememberable
,
:trackable
,
:validatable
,
:authentication_keys
=>
[
:login
]
:authentication_keys
=>
[
:login
]
VALID_PHONE_REGEX
=
/\d[0-9]\)*\z/
VALID_EMAIL_REGEX
=
/\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
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
:username
,
:presence
=>
true
,
length:
{
maximum:
50
},
:uniqueness
=>
{
:case_sensitive
=>
false
}
validates
:email
,
presence:
true
,
length:
{
maximum:
255
},
validates
:email
,
presence:
true
,
length:
{
maximum:
255
},
format:
{
with:
VALID_EMAIL_REGEX
},
format:
{
with:
VALID_EMAIL_REGEX
},
...
...
app/views/products/show.html.erb
View file @
8912f75e
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment