I'd like each ne开发者_如何学运维w title record in my application to have an ISBN field which autocompletes, using values from a table (I can import a CSV file). The trick is that each new autocompletion needs to use a unique ISBN.
In your model, use validates_uniqueness_of :isbn
Andy raises some good questions though!
If you already have the ISBN values in a table, and the ISBN is a key field (which it certainly should be, since ISBNs are unique?) then really you're not creating a new record, are you?
Wouldn't it be better to read your CSV file into your table beforehand, creating records for each of the ISBNs, and have your app update these records, rather than create new ones?
精彩评论