From: Derek Cannon Date: 2010-03-30T18:34:21+09:00 Subject: Re: Fastest Array Search? > Here is an example that shows a session, where I create several movies, > some > of which are duplicates. You see that it does not save the duplicates > because they fail this validation. Then I query the db for all the > movies it > contains, and you will see that there are no duplicate movies listed in > there. > > http://img202.imageshack.us/img202/213/picture6os.png Oh wow, thanks very much for all this work! This picture has really given me a better picture of what you mean! > You shouldn't be replicating the db in memory, and you shouldn't be > validating data outside your model like this (I assume this code is in > your controller). > > Anyway, hope that helps, and for an exceptionally good resource on > Rails, check out guides.rubyonrails.org In this particular case, the > information to create the validation was in the guide titled "Active Record Validations and Callbacks". I know there is a lot there, but with all seriousness, the time you spend reading these, and getting familiar with what is available (even if it's just to make a mental note of it, and then later look it up when you need it) will save you hundreds more time and effort (and lets not > forget frustration) in the long run. Because Rails will do things for you that > just make your life so much easier, and that you might spend several days > working on to create a slower buggier solution to something there is already a > method for, or that AR already accounts for. I speak from experience on that I'll definitely check this out. Thanks again for all the work you put into your answer. It's really helped me to better grasp some of the great features of Rails! -- Posted via http://www.ruby-forum.com/.