Forum: Ruby on Rails Validations Question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Afd161fd1de4b33cc074621572b41f0f?d=identicon&s=25 Jables (Guest)
on 2008-11-18 20:28
(Received via mailing list)
I have a script that is run by a cron job.  It is constantly trying to
put the same records into the database plus a few unique ones so to
solve this I put a validates_uniqueness_of :title on the model.  This
has the desired effect but the script exits with error on a invalid
validation (identical title).  I want it to keep going to the next
record.  How is this accomplished?

Thanks,
JB
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-18 20:35
(Received via mailing list)
On Nov 18, 7:27 pm, Jables <brun3...@uidaho.edu> wrote:
> I have a script that is run by a cron job.  It is constantly trying to
> put the same records into the database plus a few unique ones so to
> solve this I put a validates_uniqueness_of :title on the model.  This
> has the desired effect but the script exits with error on a invalid
> validation (identical title).  I want it to keep going to the next
> record.  How is this accomplished?
>
if you are using save! (which raises exceptions upon things like that)
either rescue the appropriate exception or use save (without the
exclamation mark) which returns true/false rather than raising
exceptions.

Fred
This topic is locked and can not be replied to.