2010/5/3 Sergio Cambra .:: entreCables S.L. ::. <[email protected]>:
> On Domingo, 2 de Mayo de 2010 03:41:45 Iñaki Baz Castillo escribió:
>> Hi, is it possible to automatically 'strip' string values before
>> storing them into the table? This is: removing the spaces at the
>> begining and at the end of a string field before saving it.
>> Now I do it in "before_create_save()" and "before_update_save()", but
>> it would be great an automatic field property that does automatically
>> the job.
>
> I think that feature is not used frequently to add it in core. You can do it
> in your model too, overriding coumn setter:
>
> def column=(value)
>  self[column] = value.strip
> end
>
> Also, you can make a plugin to extend ActiveScaffold with that feature.

I've got it by creating a custom class with a class method:

  class Utils
    def self.strip(value)
       value.strip!  if String === value
    end
  end

Then in before_update_save() and before_create_save() I call:

  Utils.strip(user.phone)


When I get some time I'll try to make a feature for active scaffold.

Thanks a lot.

-- 
Iñaki Baz Castillo
<[email protected]>

-- 
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" 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/activescaffold?hl=en.

Reply via email to