views:

34

answers:

3

Is there a way to make blank form inputs submit nil? Right now, I'm going through and in a before_save manually converting all "" into nil.

This really doesn't seem very DRY, and I feel like I must be missing something.

+1  A: 

I don't know if that is what you already do but look at this thread. The accepted answer seems as DRY as it gets for this problem.

nasmorn
+1  A: 

Check out the attribute_normalizer plugin.

Andrew Vit
A: 

There is no notion of "submitting nil" from a browser.

If field of name 'foo' is not submitted, then if you ask for params[:foo], it will return nil, which seems to be the behavior you desire.

Can you explain more what you want to do?

John