Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7417137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:38:25+00:00 2026-05-29T07:38:25+00:00

I gave generating test data a first shot by trying to populate my database

  • 0

I gave generating test data a first shot by trying to populate my database with a simple script that creates a sufficient number of records for my models accounting for all dependencies (esp. polymorphism).

This is my seeds.rb

require 'factory_girl_rails'

50.times do

  @user = FactoryGirl.create(:user)
  FactoryGirl.create(:contact, :user => @user)

  @question = FactoryGirl.create(:question, :user => @user)

  FactoryGirl.create(:user_answer, :question => @question, :authorable => @user)

  @contact = FactoryGirl.create(:contact, :user => @user)
  FactoryGirl.create(:contact_answer, :question => @question, :authorable => @contact)

end

As an example, here ist the question factory:

FactoryGirl.define do
  factory :question do
    title       "What is the best place to travel in " + Random.country + "?"
    body        Random.paragraphs(2)
    association :user, :method => :build
  end
end

While the Random class does produce one random term, that term remains the same for all instances created. In this case I would get 50 questions of, say, “What is the best place to travel in Spain?” and the identical two paragraphs of text for each.

What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:38:26+00:00Added an answer on May 29, 2026 at 7:38 am

    So I’m not sure where the Random class is coming from here. But I always used the Faker gem for this stuff.

    It does names, emails, cities, phone numbers: like this:

    Faker::Name.name
    Faker::Address.uk_country
    Faker::Lorem.paragraph
    

    check it out

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i gave the tree an ArrayCollection as dataprovider that i pulled from the database,
I gave up on trying to center an image vertically and horizontally. I seen
I gave a somewhat simple problem. I have a .ttf font with Cyrillic Unicode
I gave it a shot on WP7 forums @ MS and no one could
My professor gave us an assignment to test the difference in runtimes and search
I'm trying to create a report by generating a PDF based on HTML. At
I gave it a college try, but I'm stumped. I'm trying to find consecutive
I was given an excel spreadsheet that gave a rough idea of how the
Someone gave me this code that works great. But I would really like to
I gave a site full trust however I am still getting some security exceptions.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.