Forum: Ruby on Rails Removing empty fields before saving

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9f6e775366f2f607647fab8eeed66507?d=identicon&s=25 Vapor .. (vapor)
on 2009-04-01 21:06
When I save data, form submits some empty (but not null) data.
How can I remove that?

Thanks.
2505b282d57c29be797dc35b245adb4c?d=identicon&s=25 Philip Hallstrom (Guest)
on 2009-04-01 21:12
(Received via mailing list)
> When I save data, form submits some empty (but not null) data.
> How can I remove that?

Write a before_save method on your model that looks at each attribute
and if it's a blank string set it to nil.  I can't think of the name,
but someone wrote a plugin that does exactly this.
661ae6e97d0e16c2af2aaf7d197e8387?d=identicon&s=25 Sijo k g (sijo)
on 2009-04-03 13:15
plugin-

StripAttributes
This topic is locked and can not be replied to.