[Rails] Formatting data drawn from a DB
Jean-François
jf.web3 at gmail.com
Tue Apr 18 21:24:32 GMT 2006
Hello Jodi,
> you may also try this technique. You can use an after_find Model
> callback to format data.
>
> protected
> def after_find
> self.phone = "#{self.phone_before_type_cast[0..2]}-#
> {self.phone_before_type_cast[3..6]}" if !self.phone.nil? and
> self.phone_before_type_cast.length == 7
> self.phone = "(#{self.phone_before_type_cast[0..2]}) #
> {self.phone_before_type_cast[3..5]}-#{self.phone_before_type_cast
> [6..9]}" if !self.phone.nil? and self.phone_before_type_cast.length
> == 10
> end
Sorry for my arrogance, but what an ugly code !
Refactory men, where are thou ?
-- Jean-François.
--
À la renverse.
More information about the Rails
mailing list