I'm having the same problem. I want to allow people to enter a value
including a $ or £. With this method, the value of the attribute in
before_validation is zero if I enter a value with text (or a $) at the
start.
So entering $1000 is turned into 0, before before_validation.
Any ideas?
Marli Ba wrote:
> brewpoo wrote:
>> Can you post your before_validation code?
>>
>> What actually blows up? Can you also post the relevant lines from the
>> log?
>
> I am having this same problem. It seems the before_validation isn't
> working in mine:
>
>
> before_validation :normalize_phone_number
>
> validates_format_of :number, :with => /^[0-9]{10,15}$/
>
> protected
>
> def normalize_phone_number
> self.number.gsub(/-/,"").gsub(/ /,"")
> end
>
>
> The object won't save since it fails the validates_format_of since it
> never runs the before_validation. I'm running Rails 2.1.0.
>
> Any ideas?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---