"Alessandro Cauduro"
<equipe-/kv94B6L94ZwFqzsTH5u/w@public.gmane.org> writes:
> Shouldn''t the text_field("user", "name")
helper tag, generate the text max
> size based on the database max length? Otherwise, if the user types in
more
> text then is possible to be saved in the database an error will be thrown.
This level of reflection isn''t supported afaik. The way I handle this
is by essentially repeating myself. I specify column lengths in the
db scheme and then i repeat those lengths as validations in the
model. Of course, that still won''t tell the text_field helper what
size to make the input. So you really have to specify this length
three times:
create table ''foo'' {
id int(11),
fielda varchar(40)
}
validates_length_of :fielda, :within => 1..40
<%= text_field("foo", "fielda", :size => 40) %>
My understanding is that the database adapters need to be modified to
determine the column width and then set an accessor for something like
fielda_size or something. Then both the validators and html helpers
could use that.
--
doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org