Forum: Ruby on Rails AR load script only loading every other item?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Sean H. (Guest)
on 2006-01-30 20:53
(Received via mailing list)
Wow, this one is weird.  I've got a file with data I want to import,
one item per line.  When I run this code, only the first, third,
fifth, etc items get saved:

require '../app/models/entitlement'

#### Add entitlements

f ="../tmp/entitlements.csv")
f.each do |line|
  id, code, description = line.chomp.split('|')
  entitlement =
  entitlement.code = code
  entitlement.description = description

Where am I going wrong?  It's just not saving the second, fourth, etc

If I test the saving, that confirms that it's not saving, but I don't
know why:

    p "Saved #{code}"

"Saved wireless"
"Saved vpn"
"Saved trac"
"Saved svn"

The file:

1|wireless|Wireless Network
2|wirelessStudent|Student Wireless Network
4|email|Email Account
6|calendar|Calendar Account
7|svn|Source Code Repository
8|directory|Directory Listing

Any ideas?  I know I've run this import before and it's worked.


Sean H. (Guest)
on 2006-01-30 22:46
(Received via mailing list)
Answered it myself (I think).  In the model, don't put:

validates_uniqueness_of :id

I have no idea why that one just hit me now, but at least, after
removing that, everything works.

This topic is locked and can not be replied to.