On Feb 7, 7:11 am, Newb Newb <[email protected]> wrote:
> i used this private function for removing leading and trailing white
> spaces from the values.that below function would be called before_save.
> when i print the value after it strips.it prints string without any
> spaces.but in the table fields it saves with spaces .
> waht would be the problem.pls help me
>
because when you do
value = value.strip
you're not stripping whitespace from value. You are creating a new
string object that has been stripped. The @attributes hash still
contains the unstripped version.
Fred
> class CompanyInfo < ActiveRecord::Base
> before_save :strip_whitespace
>
> def strip_whitespace
> puts "strip_whitespace"
> �[email protected] do |attr,value|
> puts value
> puts "before strip"
> value = value.strip
> puts "after strip"
> puts value
> end
>
> end
> --
> Posted viahttp://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
-~----------~----~----~----~------~----~------~--~---