Forum: Ruby on Rails text_field behaviour with validations

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A28088e0bbbdecd6663d554f7be1273f?d=identicon&s=25 Wiebe Cazemier (Guest)
on 2006-04-08 17:50
(Received via mailing list)
Hi,

The text_field method sets the class of the field to "invalid" when the
object
you specified is invalid (when using validations). This is to facilitate
working with validations.

Is there anything else it does? In a certain non-standard situation I'm
forced
to use text_field_tag, instead of text_field. This means I have to take
care
of the validations myself as well. Everything goes fine, except that
when you
enter text in fields that can only take numbers, the contents of the
field is
"0" when you re-render the action, instead of the text you entered. In
parts
of the application where we use text_field, the erronious contents of
the
field is preserved on re-rendering of the action.

I don't do anything differently when extracting the contents of the
object.
Also, the part of the app where it goes OK, I tested what the type of
the
ActiveRecord field was. It was a float. So it would appear that
text_field
takes the value of the field from somewhere else when the object is not
valid,
because that erronious text could not have come from a float. Is this
true? If
so, where? I can't seem to find it.
A28088e0bbbdecd6663d554f7be1273f?d=identicon&s=25 Wiebe Cazemier (Guest)
on 2006-04-08 19:13
(Received via mailing list)
On Saturday 08 April 2006 17:48, Wiebe Cazemier wrote:

> So it would appear that text_field
> takes the value of the field from somewhere else when the object is not
> valid, because that erronious text could not have come from a float. Is this
> true? If so, where? I can't seem to find it.

I figured it out. Text_field does take it out of the ActiveRecord::Base,
but it
uses the <attribute>_before_type_cast field.
This topic is locked and can not be replied to.