Created
July 31, 2015 21:16
-
-
Save claytonflesher/708d0f1bf4eb296a40f6 to your computer and use it in GitHub Desktop.
This file contains 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 | |
desc "Add posts data to views" | |
task :seed => :environment do | |
require 'populator' | |
require 'faker' | |
tags_list = ["Ruby on Rails", "Ruby", "JavaScript", "Angular"] | |
[User, Post, Tag].each(&:delete_all) | |
User.populate 10 do |user| | |
user.email = Faker::Internet.email | |
user.encrypted_password = Faker::Internet.password(8) | |
user.sign_in_count = 10..100 | |
Post.populate 2 do |post| | |
post.title = Populator.words(3..7).titleize | |
post.body = Populator.sentences(10..20) | |
end | |
end | |
tags_list.each do |topic| | |
Tag.populate 1 do |tag| | |
tag.content = topic | |
end | |
end | |
Post.all.each do |entry| | |
PostTag.create(post: entry, tag: Tag.all.sample) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment