On 1/26/07, Fernando Poblete
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> Hello
> I need to load external data from files coming from different sources so
> I need to standardize a lot. What I want to do (after a proper file
> processing) would be something like:
>
> person.name = format_name(array[0])
> person.last_name = format_last_name(array[1])
> person.country = format_country(array[2])
> person.email = format_email(array[3])
> person.website = format_website(array[4])
>
> The thing is what most of those format_xxx methods
> (name,last_name,country,...) do is just capitalize the input so I would
> like to have a default method that catches all the format_xxx calls,
> except those that need some special formatting -like email or website-
> and that will have an ad-hoc -application level- format method.
>
> I''m thinking in adding some code to method_missing in base.rb. Is
this a
> good idea? If so, how could it be? Or is there a better way to do it?
>
> thanks
>
> PD. IT''s my first post here... great community.
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
Fernando,
I would look at the callbacks in ActiveRecord. In particular I can
see using a before_validation callback to clean the attributes as
needed.
http://caboo.se/doc/classes/ActiveRecord/Callbacks.html
Hope this helps.
--
Zack Chandler
http://depixelate.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
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
-~----------~----~----~----~------~----~------~--~---