On Tue, Mar 5, 2013 at 1:32 PM, byrnejb <[email protected]> wrote: > I have this code in a working RoR-3.1 app: > > # save > # > # Override AR save method to catch DBMS specific errors > # such as uniqueness constraint violations > def save > super > rescue ActiveRecord::StatementInvalid => this_exception > errors.add( currency_code, hll_ar_exception( this_exception ) ) > false > end > > In RoR-3.2.12 this no longer works. Once I pass a save involving a > duplicate record it never returns to the calling method. For example: > > def save > super > fail( " die die die " ) > rescue ActiveRecord::StatementInvalid => this_exception > > produces no output and does not throw an exception but in the log file I see > this none-the-less: > > PG::Error: ERROR: duplicate key value violates unique constraint > "idxu_currencies_currency_code" > DETAIL: Key (currency_code)=(JPY) already exists. > > > How do I get the old behaviour back? Calling save! instead super does not > change the outcome.
I don't know the answer to your question, but I'm wondering if you can circumvent the exception altogether by using valid? to see if it's a valid record before attempting the save? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

