Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
dhp-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
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Hoang Phuc Do
dhp-venshop
Commits
0531803a
Commit
0531803a
authored
Jun 07, 2017
by
Hoang Phuc Do
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Populating products and categories default data
parent
faf4ff28
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
0 deletions
+33
-0
Gemfile
+0
-0
app/models/category.rb
+4
-0
app/models/product.rb
+4
-0
db/seeds.rb
+25
-0
No files found.
Gemfile
View file @
0531803a
app/models/category.rb
0 → 100644
View file @
0531803a
class
Category
<
ApplicationRecord
has_many
:products
,
dependent: :destroy
end
\ No newline at end of file
app/models/product.rb
0 → 100644
View file @
0531803a
class
Product
<
ApplicationRecord
belongs_to
:category
end
\ No newline at end of file
db/seeds.rb
View file @
0531803a
...
...
@@ -5,3 +5,27 @@
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
# Create Product Categories
5
.
times
do
|
n
|
freq
=
n
+
1
title
=
"Category
#{
freq
}
"
desc
=
"Description for category
#{
freq
}
"
Category
.
create!
(
title:
title
,
description:
desc
)
end
# Create Products
categories
=
Category
.
take
(
5
)
40
.
times
do
|
n
|
freq
=
n
+
1
title
=
"Product
#{
freq
}
"
desc
=
"Description for product
#{
freq
}
"
categories
.
each
do
|
cat
|
sku
=
"u-
#{
rand
(
1
..
999
)
}
"
price
=
(
200.0
-
5.0
)
*
rand
+
5
cat
.
products
.
create!
(
title:
title
,
description:
desc
,
sku:
sku
,
price:
price
)
end
end
\ No newline at end of file
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