开发者

Ruby on Rails: Is there a way to make blank form inputs submit nil? [duplicate]

This question already has answers here: Closed 10开发者_如何学运维 years ago.

Possible Duplicate:

Make blank params[] nil

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.


Check out the attribute_normalizer plugin.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜