File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -834,7 +834,7 @@ Assigning Uncastable Values
834
834
835
835
In Mongoid 8, Mongoid has standardized the treatment of the assignment of
836
836
"uncastable" values. A value is considered "uncastable" when it cannot be
837
- coerced to the type of the assigning field. For example:
837
+ coerced to the type of the field. For example:
838
838
839
839
.. code::
840
840
@@ -1010,7 +1010,7 @@ setter methods for fields of your custom type.
1010
1010
.. note::
1011
1011
1012
1012
The ``mongoize`` method should raise a ``Mongoid::Errors::InvalidValue`` on values that
1013
- are uncastable to your custom type. Mongoid will handle catching that error
1013
+ are uncastable to your custom type. Mongoid will handle rescuing that error
1014
1014
and writing ``nil`` if the ``validate_attribute_types`` flag is turned off.
1015
1015
See the secion on :ref:`Uncastable Values <uncastable-values>` for more
1016
1016
details.
Original file line number Diff line number Diff line change @@ -176,7 +176,11 @@ def write_attribute(name, value)
176
176
typed_value = if Mongoid . validate_attribute_types
177
177
typed_value_for ( field_name , value )
178
178
else
179
- typed_value_for ( field_name , value ) rescue nil
179
+ begin
180
+ typed_value_for ( field_name , value )
181
+ rescue Errors ::InvalidValue
182
+ nil
183
+ end
180
184
end
181
185
182
186
unless attributes [ field_name ] == typed_value || attribute_changed? ( field_name )
You can’t perform that action at this time.
0 commit comments