Last active
June 19, 2016 05:19
-
-
Save Frank004/44aceed4db7bef33ae542d473f1b4a95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'ffaker', '~> 2.1.0' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :db do | |
task :populate => :environment do | |
require 'ffaker' | |
20.times do|number2| | |
@category.articles.create!( | |
title: "Faker::Name.title}#{number2}", | |
subtitle: Faker::Lorem.sentence, | |
content: Faker::Lorem.paragraph | |
) | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ffaker' | |
# este codigo corre 3 veces y crea 3 categorias con la gema de Fakker mas suma el conteo en la variable number | |
3.times do|number| | |
@category = Category.create!(name: "#{FFaker::Internet.user_name}#{number}") | |
# esta parte crea 20 articulos por categoria agraga una variable de conteo en number2 para que no se repita el mismo titulo | |
20.times do|number2| | |
@category.articles.create!( | |
title: "Faker::Name.title}#{number2}", | |
subtitle: Faker::Lorem.sentence, | |
content: Faker::Lorem.paragraph | |
) | |
end | |
end | |
#o otra opción |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@categories = ["A","B","C"] | |
@categories.each do|category| | |
@category = Category.create!(name: category) | |
20.times do|number2| | |
@category.articles.create!( | |
title: "Faker::Name.title}#{number2}", | |
subtitle: Faker::Lorem.sentence, | |
content: Faker::Lorem.paragraph | |
) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@paragraph = [ | |
"Lorem ipsum dolor sit amet, consectetur adipiscing elit.", | |
" In purus nulla, pellentesque in lorem eget, semper faucibus dolor.", | |
" Nunc sed aliquam risus, sed blandit purus.", | |
" Donec at leo porttitor, varius mauris sed, tristique urna.", | |
"Fusce non tincidunt lectus. Maecenas velit magna, semper ut iaculis non, dapibus vitae nisi." | |
] | |
@titles = [ | |
"Ladipiscing elit.", | |
"semper faucibus dolor.", | |
"sed blandit purus.", | |
"tristique urna.", | |
"emper ut iaculis non, dapibus vitae nisi." | |
] | |
@subtitles = [ | |
"Ladipiscing Ladipiscing elit.", | |
"semper Ladipiscing faucibus dolor.", | |
"vitae sed blandit purus.", | |
"SGT urna.", | |
"emper purus vitae nisi." | |
] | |
@categories = ["A","B","C"] | |
@categories.each do|category| | |
@category = Category.create!(name: category) | |
5.times do|number2| | |
@category.articles.create!( | |
title: @titles.shuffle.sample, | |
subtitle: @subtitles.shuffle.sample, | |
content: @paragraph.shuffle.sample | |
) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment