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
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
7 deletions
+12
-7
app/controllers/admin/products_controller.rb
+1
-5
app/models/admin.rb
+2
-1
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
end
def
create
@product
=
Product
.
new
(
name:
params
[
:product
][
:name
],
category_id:
params
[
:product
][
:category_id
].
to_i
,
price:
params
[
:product
][
:price
].
to_i
,
image:
params
[
:product
][
:image
],
description:
params
[
:product
][
:description
])
@product
=
Product
.
new
(
product_params
)
if
@product
.
check_valid
()
@product
.
save
flash
[
:success
]
=
"Create product : Success"
...
...
app/models/admin.rb
View file @
79799b81
...
...
@@ -5,13 +5,14 @@ class Admin < ActiveRecord::Base
devise
:database_authenticatable
,
:registerable
,
:recoverable
,
:rememberable
,
:trackable
,
:validatable
,
:authentication_keys
=>
[
:login
]
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
:email
,
presence:
true
,
length:
{
maximum:
255
},
format:
{
with:
VALID_EMAIL_REGEX
},
uniqueness:
{
case_sensitive:
false
}
before_save
:downcase_email
def
self
.
find_for_database_authentication
(
warden_conditions
)
conditions
=
warden_conditions
.
dup
if
login
=
conditions
.
delete
(
:login
)
...
...
app/models/product.rb
View file @
79799b81
...
...
@@ -4,7 +4,6 @@ class Product < ActiveRecord::Base
belongs_to
:category
has_many
:cart_products
before_destroy
:ensure_not_referenced_by_any_cart_product
VALID_NUMBER_REGEX
=
/\A[+-]?\d+\Z/
...
...
@@ -13,6 +12,9 @@ class Product < ActiveRecord::Base
validates
:description
,
presence:
true
,
length:
{
maximum:
65535
}
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
if
self
.
price
<
0
return
false
...
...
@@ -23,6 +25,7 @@ class Product < ActiveRecord::Base
if
self
.
image
==
nil
return
false
end
return
true
end
def
self
.
search
(
keyword
)
...
...
@@ -39,4 +42,9 @@ class Product < ActiveRecord::Base
return
false
end
end
def
convert_data_product
self
.
category_id
.
to_i
self
.
price
.
to_i
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