On Wed, March 6, 2013 04:54, Frederick Cheung wrote:
>
> As an aside recent versions of rails raise
> ActiveRecord::RecordNotUnique in
> such cases, although this is a subclass of
> ActiveRecord::StatementInvalid
> so shouldn't change behaviour as far as you're concern. You're also
> changing the signature of save although I don't think that is related
> to the problem at hand.
>


On: Tue Mar 5, 2013 1:48 pm ((PST)), "Les Nightingill"
[email protected] lesnightingill wrote:
>
> perhaps the exception being raised is not
> ActiveRecord::StatementInvalid.
>
> suggest trying rescue with no exception specified to see if there is a
> different exception being raised.
>
> Les


Bingo!  Rails-3.2.12 implements code similar to that I was providing
in  hll_ar_exception( this_exception ) ) and actually returns the
exact message from PG that I was checking for therein.

  def save( * )
    begin
      puts( "I go" )
      super
      puts( "I return" )
    rescue => e
      puts( e.inspect )
      false
    end
  end


Using the default profile...
.................I go
#<ActiveRecord::RecordNotUnique: PG::Error: ERROR:  duplicate key
value violates unique constraint "idxu_currencies_currency_code"
DETAIL:  Key (currency_code)=(JPY) already exists.
: INSERT INTO "currencies" ("changed_at", "changed_by", "created_at",
"created_by", "currency_code", "currency_name", "discount_factor",
"effective_from", "fx_accounting_factor", "fx_accounting_margin",
"is_payable", "is_receivable", "premium_factor", "superseded_after")
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)
RETURNING "id">
..F-

(::) failed steps (::)

Mystery solved.  Thanks.

-- 
***          E-Mail is NOT a SECURE channel          ***
James B. Byrne                mailto:[email protected]
Harte & Lyne Limited          http://www.harte-lyne.ca
9 Brockley Drive              vox: +1 905 561 1241
Hamilton, Ontario             fax: +1 905 561 0757
Canada  L8E 3C3

-- 
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.


Reply via email to