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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nick wrote:> 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? >property.price_before_type_case> Thanks! > Nick > > > >-- Jack Christensen jackc-/SOt/BrQZzMOf2zXYvRtkodd74u8MsAO@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Oct 10, 10:26 am, Jack Christensen <ja...-/SOt/BrQZzMOf2zXYvRtkodd74u8MsAO@public.gmane.org> wrote:> property.price_before_type_caseGreat, thanks Jack! That solved it. -Nick --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Oct 10, 2008, at 10:26 AM, Jack Christensen wrote:> Nick wrote: >> 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? >> > property.price_before_type_caseThat''s: ...before_type_cast (not _case)>> Thanks! >> Nick >>> >> > -- > Jack Christensen > jackc-/SOt/BrQZzMOf2zXYvRtkodd74u8MsAO@public.gmane.orgYou''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 Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---