Using the newly created value in faker gem

require ‘faker’
require ‘populator’
require ‘date’


100.times do
u =
u.username = Faker::Internet.user_name =
u.password = “test”
u.password_confirmation = “test”
I am using the Faker gem to load sample data in my app. I have three
models, user, dbase and table.
The table gets created under every dbase so I want it’s column ‘dbase’
tp have the same value as the that was created above.
Please see the code :

10.times do
u = User.find(id = rand(User.count))
db = =
db.vendor =
db.location = [ ,
Faker::Address.us_state_abbr ].join(’.’)
db.port = 50000
db.defuser = u.username
t1 =
Table.populate(rand(10)) do |tab|
tab.schema_name = t1
tab.tab_name =

  tab.dbase =     #here it says undefined method `db' for


  tab.created_by =
  tab.created_on =
  tab.logged = rand(2)


I can accompolish the same using rails console so I am assuming the
console holds the value in cache while this doesn’t commit or

Can anyone help on how to accomplish this?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs