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
79799b81
Commit
79799b81
authored
Aug 03, 2015
by
Nguyen Quoc Kien
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix code admin: add products
parent
d895a13f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
9 deletions
+14
-9
app/controllers/admin/products_controller.rb
+1
-5
app/models/admin.rb
+4
-3
app/models/product.rb
+9
-1
No files found.
app/controllers/admin/products_controller.rb
View file @
79799b81
...
@@ -26,11 +26,7 @@ class Admin::ProductsController < ApplicationController
...
@@ -26,11 +26,7 @@ class Admin::ProductsController < ApplicationController
end
end
def
create
def
create
@product
=
Product
.
new
(
name:
params
[
:product
][
:name
],
@product
=
Product
.
new
(
product_params
)
category_id:
params
[
:product
][
:category_id
].
to_i
,
price:
params
[
:product
][
:price
].
to_i
,
image:
params
[
:product
][
:image
],
description:
params
[
:product
][
:description
])
if
@product
.
check_valid
()
if
@product
.
check_valid
()
@product
.
save
@product
.
save
flash
[
:success
]
=
"Create product : Success"
flash
[
:success
]
=
"Create product : Success"
...
...
app/models/admin.rb
View file @
79799b81
...
@@ -5,13 +5,14 @@ class Admin < ActiveRecord::Base
...
@@ -5,13 +5,14 @@ class Admin < ActiveRecord::Base
devise
:database_authenticatable
,
:registerable
,
devise
:database_authenticatable
,
:registerable
,
:recoverable
,
:rememberable
,
:trackable
,
:validatable
,
:authentication_keys
=>
[
:login
]
:recoverable
,
:rememberable
,
:trackable
,
:validatable
,
:authentication_keys
=>
[
:login
]
VALID_EMAIL_REGEX
=
/\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
VALID_EMAIL_REGEX
=
/\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
before_save
:downcase_email
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
},
uniqueness:
{
case_sensitive:
false
}
uniqueness:
{
case_sensitive:
false
}
before_save
:downcase_email
def
self
.
find_for_database_authentication
(
warden_conditions
)
def
self
.
find_for_database_authentication
(
warden_conditions
)
conditions
=
warden_conditions
.
dup
conditions
=
warden_conditions
.
dup
if
login
=
conditions
.
delete
(
:login
)
if
login
=
conditions
.
delete
(
:login
)
...
@@ -26,5 +27,5 @@ class Admin < ActiveRecord::Base
...
@@ -26,5 +27,5 @@ class Admin < ActiveRecord::Base
def
downcase_email
def
downcase_email
self
.
email
=
email
.
downcase
self
.
email
=
email
.
downcase
end
end
end
end
app/models/product.rb
View file @
79799b81
...
@@ -4,7 +4,6 @@ class Product < ActiveRecord::Base
...
@@ -4,7 +4,6 @@ class Product < ActiveRecord::Base
belongs_to
:category
belongs_to
:category
has_many
:cart_products
has_many
:cart_products
before_destroy
:ensure_not_referenced_by_any_cart_product
VALID_NUMBER_REGEX
=
/\A[+-]?\d+\Z/
VALID_NUMBER_REGEX
=
/\A[+-]?\d+\Z/
...
@@ -13,6 +12,9 @@ class Product < ActiveRecord::Base
...
@@ -13,6 +12,9 @@ class Product < ActiveRecord::Base
validates
:description
,
presence:
true
,
length:
{
maximum:
65535
}
validates
:description
,
presence:
true
,
length:
{
maximum:
65535
}
validates
:price
,
presence:
true
,
format:
{
with:
VALID_NUMBER_REGEX
}
validates
:price
,
presence:
true
,
format:
{
with:
VALID_NUMBER_REGEX
}
before_destroy
:ensure_not_referenced_by_any_cart_product
before_save
:convert_data_product
def
check_valid
def
check_valid
if
self
.
price
<
0
if
self
.
price
<
0
return
false
return
false
...
@@ -23,6 +25,7 @@ class Product < ActiveRecord::Base
...
@@ -23,6 +25,7 @@ class Product < ActiveRecord::Base
if
self
.
image
==
nil
if
self
.
image
==
nil
return
false
return
false
end
end
return
true
end
end
def
self
.
search
(
keyword
)
def
self
.
search
(
keyword
)
...
@@ -39,4 +42,9 @@ class Product < ActiveRecord::Base
...
@@ -39,4 +42,9 @@ class Product < ActiveRecord::Base
return
false
return
false
end
end
end
end
def
convert_data_product
self
.
category_id
.
to_i
self
.
price
.
to_i
end
end
end
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