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 7995313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:22:27+00:00 2026-06-04T14:22:27+00:00

I’m currently going through the RoR guides, and i’m stuck at… Adding following/follower relationships

  • 0

I’m currently going through the RoR guides, and i’m stuck at…

“Adding following/follower relationships to the sample data.”

Here’s the code that is suppose to work: sample_app/lib/task/sample_data.rake

namespace :db do
desc "Fill database with sample data"
task populate: :environment do
    make_users
    make_microposts
    make_relationships
  end
end

def make_users
 admin = User.create!(name:     "Example User2",
                     email:    "example2@railstutorial.org",
                     password: "foobar",
                     password_confirmation: "foobar")
admin.toggle!(:admin)
99.times do |n|
 name  = Faker::Name.name
 email = "example-#{n+1}@railstutorial.org"
 password  = "password"
 User.create!(name:     name,
              email:    email,
              password: password,
              password_confirmation: password)
  end
end

def make_microposts
  users = User.all(limit: 6)
  50.times do
    content = Faker::Lorem.sentence(5)
    users.each { |user| user.microposts.create!(content: content) }
  end
end

def make_relationships
  users = User.all
  user  = users.first
  followed_users = users[2..50]
  followers      = users[3..40]
  followed_users.each { |followed| user.follow!(followed) }
  followers.each      { |follower| follower.follow!(user) }
end

when i do rake db:reset my database reset with no problems.

when i do rake db:populate an error occurred stating this:

 rake aborted!
 Validation failed: Follower can't be blank`

so i checked my database, and all tables were populated except for “relationships” table.. any thoughts or suggestions? I’m pretty sure there’s a problem with the code, def making_relationships, to be exact. hope anyone has a solution to this..

-Marc

  • 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-06-04T14:22:28+00:00Added an answer on June 4, 2026 at 2:22 pm

    Since you’re calling .create! on models like User and Micropost (user.microposts), it is one of them throwing the error mentioned.

    Please, post the code for these models to enable us answer more specifically.

    You can still debug the problem by yourself though. Just hit rails c in the projects root directory, and try to create instances with the very same attributes you’re trying in rake task:

    $ rails c
    
    $ user = User.create!(name:     name,
                          email:    email,
                          password: password,
                          password_confirmation: password)
    
    $ micropost = user.microposts.create!(content: "Hello, cruel world!")
    
    # by this step you should already see some errors raised; if that's not sufficient,
    # call the following methods to figure out what model suffers the validation error
    user.errors.full_messages
    micropost.errors.full_messages
    

    Anyway, it’s the validation that’s not satisfied. Double check you’re passing all required attributes passed when creating a model with a shebang create!. Specifically check which model requires presence of Follower (whatever that is).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to construct a data frame in an Rcpp function, but when I
I'm parsing an XML file, the creators of it stuck in a bunch social
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.