Skip to content

Instantly share code, notes, and snippets.

@gringocl
Last active January 4, 2016 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gringocl/8678183 to your computer and use it in GitHub Desktop.
Save gringocl/8678183 to your computer and use it in GitHub Desktop.
Ffaker gem Seeds for Q and A site
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
require 'ffaker'
def sample_text
(1..10).map{|i|"<p>#{Faker::HTMLIpsum.fancy_string}</p>"}.join
end
15.times do
User.new.tap do |u|
u.email = Faker::Internet.email
u.password = 'password'
u.name = Faker::Name.name
u.save!
end
end
50.times do
Question.new.tap do |q|
q.title = Faker::HipsterIpsum.sentence
q.body = sample_text
q.answer = sample_text
q.save!
end
end
300.times do
user = User.order( 'RANDOM()' ).first
question = Question.order( 'RANDOM()' ).first
user.questions << question
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment