Rails simple_form 属性需要标记 (*)
我在我的应用程序中使用简单表单,我想删除 *
以指示我的所有表单(现有表单和尚未创建的表单)都需要一个属性。
我尝试在 simple_form.rb
中设置:
# Whether attributes are required by default (or not). Default is true.
config.required_by_default = false
并且我尝试修改 simple_form.en.yml
:
required:
text: 'required'
mark: '' # <------ tried setting this to blank.
我知道我可以设置 :required =>; false
在每个字段上,但我想清理视图和设置一次。
I am using Simple Form in my app and I'd like to remove the *
to indicate an attribute is required on all of my forms (existing and those yet to be created).
I have tried to set in simple_form.rb
:
# Whether attributes are required by default (or not). Default is true.
config.required_by_default = false
And I've tried to modify simple_form.en.yml
:
required:
text: 'required'
mark: '' # <------ tried setting this to blank.
I know I can set :required => false
on each field, but I want to clean up the views & set it once.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您重新启动服务器,则将
simple_form.required.mask
设置为''
应该可以工作。但您可以通过更改配置来删除它
:
Setting the
simple_form.required.mask
to''
should work if you restarted the server.But you can remove it changing the the configuration:
to
你也可以做
You can also do
在 Rails 4 上只需删除“必需”一词
,因此验证
仍然有效!
on Rails 4 just remove the "required" word
so it should be
Validation still works!
只是
<代码>
# 默认情况下是否需要属性。默认为 true。
config.required_by_default = false
并重新启动您的 Rails 服务器。然后就可以了。
just
# Whether attributes are required by default (or not). Default is true.
config.required_by_default = false
and restart your rails server. Then it works.