Andrew Timberlake wrote:
> In your model do
>
> def web_color(web_color)
> web_color = nil if web_color.blank?
> write_attribute(:web_color, web_color)
> end
>
> and the same for thumbnail_path
>
> Andrew Timberlake
> http://ramblingsonrails.com
>
> http://MyMvelope.com - The SIMPLE way to manage your savings
Thanks Andrew - presumably you meant
def web_color=(web_color)
I ended up doing this:
before_validation :set_nils
def set_nils
self.web_color = nil if self.web_color.blank?
self.thumbnail_path = nil if self.thumbnail_path.blank?
end
Originally i had it using a before_save callback but this didn't work as
the object state with web_color = "" was failing the validation before
getting to the before_save, but with the before_validation it works.
However your way is cleaner so i'll do that instead.
thanks!
max
--
Posted via http://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
-~----------~----~----~----~------~----~------~--~---