In the following logic
if @official.save
...
else
...
end
the save method causes activerecord to throw an exception, instead of returning false with an error added to @official.errors;
When I change to
begin
@official.save
redirect_to '/success.xml'
rescue ActiveRecord::StatementInvalid => exception
redirect_to '/failure.xml'
end
the exception value is the full tiny_tds error string, as excerpted below:
(TinyTds::Error: Violation of PRIMARY KEY constraint 'PK_eo'. Cannot insert duplicate key in object 'dbo.eo'. The duplicate key value is (01001 , 1).: EXEC sp_executesql N'INSERT INTO [Eo] ([address1], [address2], [city], [createdate], [createuid], [dir_phone], [dir_phone_ext], [email], [eotypeID], [fax], [firstname], [jurisdictionID],
etc.
Is there a way to have the save return false and have the key constraint violation message returned in an object errors attribute?
Thanks for any ideas.