# Allow a "$" in a price field

**URL:** <https://www.ruby-forum.com/t/allow-a-in-a-price-field/150620>\
**Category:** Rails\
**Created:** [October 10, 2008, 3:10pm UTC](https://www.ruby-forum.com/t/allow-a-in-a-price-field/150620 "2008-10-10T15:10:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f9ae1b/32.png) [@nick](https://www.ruby-forum.com/u/nick)\
**Post date:** [October 10, 2008, 3:10pm UTC](https://www.ruby-forum.com/t/allow-a-in-a-price-field/150620/1 "2008-10-10T15:10:02Z")

</div>

Hi guys. My Property model has a “price” attribute, which is an  
integer. When creating a property, I’d like users to be able to submit  
“$1234” as the price, and have my app remove the “$”.

I thought this could be accomplished by having a before\_validation  
callback on the “price” attribute remove the “$”. Unfortunately, by  
the time the callback is executed, the submitted price has been cast  
to a Fixnum. This means that any price beginning with a “$” is  
converted to 0 (zero).

Does anyone have any suggestions for how to do this?

Thanks!  
Nick

---

<div class="post-metadata">

**Author:** ![nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f9ae1b/32.png) [@nick](https://www.ruby-forum.com/u/nick)\
**Post date:** [October 10, 2008, 4:27pm UTC](https://www.ruby-forum.com/t/allow-a-in-a-price-field/150620/2 "2008-10-10T16:27:06Z")

</div>

Nick wrote:

> Does anyone have any suggestions for how to do this?

property.price\_before\_type\_case

> Thanks!  
> Nick
> 
> >

–  
Jack C.  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f9ae1b/32.png) [@nick](https://www.ruby-forum.com/u/nick)\
**Post date:** [October 10, 2008, 6:19pm UTC](https://www.ruby-forum.com/t/allow-a-in-a-price-field/150620/3 "2008-10-10T18:19:12Z")

</div>

On Oct 10, 10:26 am, Jack C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> property.price\_before\_type\_case

Great, thanks Jack! That solved it.  
-Nick

---

<div class="post-metadata">

**Author:** ![nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f9ae1b/32.png) [@nick](https://www.ruby-forum.com/u/nick)\
**Post date:** [October 10, 2008, 6:51pm UTC](https://www.ruby-forum.com/t/allow-a-in-a-price-field/150620/4 "2008-10-10T18:51:32Z")

</div>

On Oct 10, 2008, at 10:26 AM, Jack C. wrote:

> > converted to 0 (zero).
> > 
> > Does anyone have any suggestions for how to do this?
> 
> property.price\_before\_type\_case

That’s: …before\_type\_cast (not \_case)

> > Thanks!  
> > Nick
> > 
> > >
> 
> –  
> Jack C.  
> removed\_email\_address@domain.invalid

You’ll still have to deal with the original string value of the field,  
of course, but it seems that’s exactly what you want.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
