I’m having a hell of a time figuring out what is going on here.
I’m trying to override one of my getters so that I can format it a
certain way in my form. But I can’t seem to get text_field to call the
appropriate method on my object.
So here’s my getter:
public
def FAX
fax = read_attribute(:FAX)
puts fax
sprintf("(%d)%d-%d", fax[0,3], fax[3,3], fax[6,4])
“crap”
end
You could also just use text_field_tag for this. Its a little
annoying to not get the automated form fills with text_field but you
can get around it with text_field_tag.
-Ezra
Thanks, I see that now.
You can:
specify :value => @object.method on the text_field tag
use text_field_tag
Implement custom display getter/setter pair to front the real
getter/setter pair.
Do you understand the reasoning behind this - I think it’s so that if a
user types something into a form that is invalid, then when the form
refreshes (with their errors), they still see what they typed, not some
modified version of it.
Is that right? Is this a consequence of setting the attributes on the
object before validation occurs? If the value isn’t valid, then it
probably shouldn’t be set on the object at all.
I’m not saying we need JavaBeans/form beans here, I’m just sayin’ :).
You could also just use text_field_tag for this. Its a little
annoying to not get the automated form fills with text_field but you
can get around it with text_field_tag.
-Ezra
Thanks, I see that now.
You can:
specify :value => @object.method on the text_field tag
use text_field_tag
Implement custom display getter/setter pair to front the real
getter/setter pair.
Do you understand the reasoning behind this - I think it’s so that if a
user types something into a form that is invalid, then when the form
refreshes (with their errors), they still see what they typed, not some
modified version of it.
Is that right? Is this a consequence of setting the attributes on the
object before validation occurs? If the value isn’t valid, then it
probably shouldn’t be set on the object at all.
I’m not saying we need JavaBeans/form beans here, I’m just sayin’ :).
Am I on the right track?
Thanks,
WG
You know what - this totally sucks.
I have 4 form fields that are actually two database fields that are
split into two fields each.
So I wrote my 4 getters to split apart the 2 fields so that I could
display them, but because they aren’t REAL attributes on the AR
object, they get cleared out on the redisplay.
The validation runs for them, but then they get cleared out.
That is BS. The validation runs on the view facade methods, but the
helpers go to the underlying data? WTF?
What am I not getting?
WG
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.