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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:46:39+00:00 2026-06-08T06:46:39+00:00

I have a seed file with the following code within it: 300.times do #

  • 0

I have a seed file with the following code within it:

300.times do
  # create the customer
  customer = Customer.create([
    {customer_type_id: '1'}
  ])

  # create an address for the customer
  address = Address.create([
    {city: Faker::Address.city, country: 'UK'}
  ])
  postcode = Postcode.create([
    {value: Faker::Address.uk_postcode}
  ])
  name_number = NameNumber.create([
    {value: Random.rand(495)}
  ])
  street = Street.create([
    {value: Faker::Address.street_name + " " + Faker::Address.street_suffix}
  ])
  state = State.create([
    {value: Faker::Address.uk_county}
  ])

This works fine. I had hoped, however, to be able to do the following:

address = Address.create([
  {city: Faker::Address.city, country: 'UK'}
])
address.postcode = Postcode.create([
  {value: Faker::Address.uk_postcode}
])

Where I have created the address in the first line, and I am creating the postcode for the address in the second line. This, however, generates an error.

Could anyone suggest how I can do this?

Thanks!

EDIT: As requested, the error generated is:

rake db:seed
rake aborted!
undefined method `postcode=' for #<Array:0x007f9df1f26818>

Tasks: TOP => db:seed
(See full trace by running task with --trace)
  • 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-08T06:46:40+00:00Added an answer on June 8, 2026 at 6:46 am

    You’re passing an array to create, which creates one object for each hash of attributes in the array and returns the resulting array of objects. Since you’re only creating one object at a time, simply remove the square brackets around your hash of attributes (and even the curly braces if you want) and it should work correctly:

    address = Address.create(city: Faker::Address.city, country: 'UK')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CSV file in the following format: id,code,date,address,complete_url Example data from the
I have the following seeds.rb file: initial_users = User.create( [ { :first_name => Joe,
Right now, in development I have the following code in the Global.asax.cs file that
I have the following code in my seeds.rb file in a jruby 1.6.3 rails
I have state data in a txt file that I used to seed my
I have this code, i'm trying to set the identity seed by a varable
I have an XML file containing seed data that I'm trying to load into
I have the following db:seed which is live on heroku: [Admin, Member].each do |role_name|
In my seed file I am trying to create 3 users, 1 admin and
I have the following code I created with help of asp.net mvc tutorials. These

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.