Ruby on Rails:有没有办法让空白表单输入提交 nil?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 attribute_normalizer 插件。
Check out the attribute_normalizer plugin.
浏览器中不存在“提交 nil”的概念。
如果名称为“foo”的字段未提交,那么如果您请求 params[:foo],它将返回 nil,这似乎是您想要的行为。
你能解释一下你想做什么吗?
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?