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
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
9 additions
and
49 deletions
+9
-49
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
+1
-1
No files found.
app/controllers/cart_products_controller.rb
View file @
8912f75e
...
...
@@ -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
app/controllers/carts_controller.rb
View file @
8912f75e
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
)
...
...
app/controllers/products_controller.rb
View file @
8912f75e
...
...
@@ -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
...
...
app/controllers/static_pages_controller.rb
View file @
8912f75e
class
StaticPagesController
<
ApplicationController
def
home
end
def
help
end
def
about
end
end
app/models/cart.rb
View file @
8912f75e
...
...
@@ -19,8 +19,4 @@ class Cart < ActiveRecord::Base
def
downcase_email
self
.
email
=
email
.
downcase
end
def
check_valid
end
end
app/models/cart_product.rb
View file @
8912f75e
...
...
@@ -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
app/models/user.rb
View file @
8912f75e
...
...
@@ -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
},
...
...
app/views/products/show.html.erb
View file @
8912f75e
...
...
@@ -6,7 +6,7 @@
<%=
image_tag
(
@product
.
image
,
alt:
@product
.
name
,
class:
"img-responsive"
)
%>
<br>
<hr>
<div
class=
"caption-full"
>
<br/>
<br/>
<h4><b>
<%=
@product
.
name
%>
</b></h4>
<p>
<%=
simple_format
(
@product
.
description
)
%>
</p>
<h3>
...
...
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