0

I wonder why the first data which is the agency, wasn't saved even if the syntax is just really correct.

Please take a look at my seed file:

db/seeds.rb

Agency.delete_all
puts "Creating agency: agency@example.com..."
Agency.create(email: 'agency@example.com', password: 'password')
puts "Done!\n\n"


Admin.delete_all
puts "Creating admin: admin@example.com..."
Admin.new
Admin.create(email: 'admin@example.com', password: 'password')
puts "Done!\n\n"

When I entered into the console, and hitted User.all

only the last data was saved and that was "admin"

xirukitepe
  • 1,575
  • 7
  • 26
  • 54
  • 1
    Where are you saving a `User` object on your seed? – hyperrjas Jan 28 '13 at 13:19
  • try to use `create!` instead of `create`. It will raise an exception if the create fails, providing you helpfull details (record invalid, etc...) – m_x Jan 28 '13 at 13:21
  • Already tried with or without the bang "!". @m_x . I tried without `delete_all` & it worked... but i dont understand why it isnt working with the delete_all.. – xirukitepe Jan 28 '13 at 13:23
  • there may be some validations which are not allowed to create new `Agency` so use `create!` as suggested by m_x – Salil Jan 28 '13 at 13:24
  • actually, the first version of the seed file has `create!` but it also didn't work. Tried without delete_all and it worked. Please explain to me, what could be the reason... – xirukitepe Jan 28 '13 at 13:25
  • 1
    is there any relation between `agency` and `admin` if yes there is chance of agency deletion when you are using `Admin.delete_all` – Salil Jan 28 '13 at 13:26
  • Thank you but i didnt put any relations. anyway thanks for all suggestions – xirukitepe Jan 28 '13 at 13:41

1 Answers1

0

Thanks for all your suggestions...

I tried removing the delete_all and it worked.

Sorry for such novice questions.

xirukitepe
  • 1,575
  • 7
  • 26
  • 54