I have a model that looks like this:
class Assessment < ActiveRecord::Base
validates_presence_of :Name, :Description, :Version
validates_length_of :Name, :maximum => 50
My setup is windows server 2003 R2, RoR 1.1.6, and SQL Server 2005.
When I intentionally enter a string that is greater than 50 characters,
the write to the database is still attempted, and the user sees an ugly
error like this:
ActiveRecord::StatementInvalid in AssessmentsController#create
OLE error code:80040E57 in Microsoft OLE DB Provider for SQL Server
String or binary data would be truncated.
HRESULT error code:0x80020009
Exception occurred.: INSERT INTO SHAKERCG_Assessment ([Name],
[Version], [State], [Customer_ID_FK], [Description]) VALUES(‘this is my
new assessment with a really long name.’, ‘1’, NULL, 1, ‘hello’)
Application Trace | Framework Trace | Full Trace
I want the user to see the flash[:notice] message in a
that I have created in the page template. Instead, they are directed to
this type of page. Because this is a legacy schema, the primary key and
table names must all be overriden. I don’t know this is happening
because of SQL Server, or because of not being able to use the RoR
I also tried wrapping the save call around a begin/rescue block, hoping
to catch the exception (changing to a .save! vs. .save), but that didn’t
seem to help either.