Forum: Ruby on Rails Setting blank params to nil

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.
Chris F. (Guest)
on 2007-02-03 05:40
Hi...

Got a quick question about a before_filter routine I'm setting up in
Rails

I'm a RoR newbie coming from the PHP world and I normally "clean" POSTed
input from forms by looping through the form submission and setting any
blank strings to NULL for database processing.

I'm trying to do something similiar in Rails with the following
before_filter in my "PeopleController"

before_filter params[:person].delete_if { |key, value| value == "" } if
@params

This (and the multiple permutations that I've tried) doesn't seem to be
working, which is having the side effect of tripping any of my
validations that are set to :allow_nil

I guess I'm missing something simple because my eyes are now crossed
re-working this line of code so many times.

Any suggestions?  Thanks

Chris
Chris F. (Guest)
on 2007-02-03 05:56
Arrrgh...I figured out that posting back via an AJAX form isn't hitting
the before_filter.

I'll have to define that as a method and call it explicitly from my AJAX
updater / inserter.
This topic is locked and can not be replied to.