activeadmin 表单中所需的输入不起作用

Phi*_*899 6 ruby-on-rails formtastic activeadmin ruby-on-rails-5

我正在使用 active_admin。我正在尝试在 activeadmin 中创建一个表单字段:

  input :team, as: :select, required: true, collection: Team.all.pluck(:name, :id), include_blank: "Please enter a team", allow_blank: false
Run Code Online (Sandbox Code Playgroud)

只有在这个特定的 activeadmin 页面上,我才需要此验证。它不应该存在于站点的其他任何地方,所以我不想在模型中这样做。

出于某种原因,上面的代码不起作用。虽然表单字段确实显示了*,但它仍然提交。如何仅在此页面上需要此输入?

AFO*_*FOC 5

你需要的是input_html: {required: true}

# adds .required class to the input's enclosing <li> element - form can still be submitted
input :team, required: true   

# adds required attribute to the <input> element - form cannot be submitted
input :team, input_html: {required: true} 
Run Code Online (Sandbox Code Playgroud)