Raul,

I took the validation code for the credit card out of  
before_validation_on_create and wrote a separate method for it. and  
just called it with

before_validation :normalize_cc_number

This is my custom method:

def normalize_cc_number
     self.credit_card = credit_card.gsub(/[^0-9]/, "") if  
attribute_present?("credit_card")
end

That did the trick

Thanks heaps for the respond...

On 08/12/2008, at 8:45 AM, raul parolari wrote:

>
> Vvan,
>
>   If you are using a regexp that was used to process 'digits +  
> spaces..', it is not surprising that if fails for a string with   
> 'alpha chars + spaces'.
>
> However, as we are weak in divine powers, it would help if you  
> showed the code that you are using, rather than saying "it is  
> similar as for the credit card"..:-)
>
> Raul
>
>
> On Sat, Dec 6, 2008 at 12:19 AM, vvan <[email protected]> wrote:
>
> Hi all,
>
> I have been searching in the previous posts but could not find an
> answer to my problem.
>
> During the lab exercises for this chapter we wrote a
> before_validation_on_create method and stripped everything from the
> 'name' attribute but left alphabets...
> I added another line of code to that for the credit card format which
> strips everything but numbers.
>
> Credit card part works perfectly fine but now the name part of it
> doesn't work. Meaning if the name entered is 'Volkan Van' it gets
> saved as 'Volkan Van' instead of 'VolkanVan'
>
> Could this be because there can be code only belonging to one
> attribute or am I completely of track?
>
>
> Thank in Advance for any help
>
> >
>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "ruby-on-rails-programming-with-passion" group.
To unsubscribe from this group, send email to
ruby-on-rails-programming-with-passion-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/ruby-on-rails-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to