# Xxxx\_before\_type\_cast and form\_helper methods

**URL:** <https://www.ruby-forum.com/t/xxxx-before-type-cast-and-form-helper-methods/69167>\
**Category:** Rails\
**Created:** [September 19, 2006, 3:29am UTC](https://www.ruby-forum.com/t/xxxx-before-type-cast-and-form-helper-methods/69167 "2006-09-19T03:29:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [September 19, 2006, 3:29am UTC](https://www.ruby-forum.com/t/xxxx-before-type-cast-and-form-helper-methods/69167/1 "2006-09-19T03:29:57Z")

</div>

Can anyone explain why the \_before\_type\_cast method is  
called in the constructor of InstanceTag such that all of the form  
helper methods use the “uncast” attribute value?

I know there’s a reason but have no idea what it is.

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [September 19, 2006, 10:36pm UTC](https://www.ruby-forum.com/t/xxxx-before-type-cast-and-form-helper-methods/69167/2 "2006-09-19T22:36:43Z")

</div>

This is kind of annoying as I have a different format that I want to  
display my form fields with and I have to use a helper now to do the  
formatting instead of being able to handle it in my model object.

Anybody know why xxx\_before\_type\_cast is used?

Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [September 20, 2006, 1:57am UTC](https://www.ruby-forum.com/t/xxxx-before-type-cast-and-form-helper-methods/69167/3 "2006-09-20T01:57:12Z")

</div>

Maybe there should be a way to disallow overriding the attribute getters  
since they aren’t used by the form\_helpers anyway. That probably  
doesn’t make sense, but…

I’ve “re-discovered” the fact that xxx\_before\_type\_cast is used to pull  
the attribute values for form helpers at least 5 times in the last 2  
months because it is so non-intuitive. I really have to question this  
behavior.

It seems like if I _want_ to modify an attribute “on the way out” of the  
database that I should be able to do that without having to resort to  
another attribute. It feels very natural for me to override the  
accessors (very OO) so this is why I keep forgetting that it doesn’t  
work.

Apparently, the argument for using \_before\_type\_cast has something to do  
with these accessor methods doing conversions on the input data and then  
the form input value being changed “out from under” the user. Why can’t  
we as users just be responsible for making sure that doesn’t  
happen/handling our own data conversions?

I have the opposite problem - I _want_ to store my data in a different  
format in the database than my display format and so I _want_ to  
translate on the way in and out.

We already have the ability to use read\_attribute(:attribute\_name) when  
we want to get the database value of the attribute. Why do we need AR  
to force this type of access on us?

My gut feeling is that AR may only be called an OR mapping nominally  
since certain access paths and initialization are non-standard.

Thanks,  
Wes
