Rails:在 simple_form 中收集所需的属性 [英] Rails: Attribute required for collection in simple_form

查看:49
本文介绍了Rails:在 simple_form 中收集所需的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试在 simple_form 中设置 required.以下设置不起作用.

We are trying to set required in simple_form. The following setup does not work.

<%= f.input :payee_id, :label => t('Payee'), required: true, :collection => BankAccountx.payee_class.where(active: true).map {|x| [x.name, x.id]}, :selected => params[:payee_id], include_blank: true %>

也试过 :input_html =>{required: true} 并且效果不佳.

Also tried :input_html => {required: true} and it did not work as well.

在 simple_form 中设置 required 的正确方法是什么?

What's the right way to set required in simple_form?

推荐答案

找到了.如果你使用这个命令:

Found it. If you use this command:

rails generate simple_form:install

它将在 config/initializer/simple_form.rb 中创建一个文件.找到这一行

It will create a file at config/initializer/simple_form.rb. Find this line

config.browser_validations = false

并将其更改为 true.注意:如果你只是添加 gem 而不运行 rails generate,它默认工作.

And change it to true. NOTE: If you just add the gem and not run rails generate, it works by default.

这篇关于Rails:在 simple_form 中收集所需的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆