Ruby on rails 如何使用Mongoid在formtastic中设置单数复选框?
在我的模型中Ruby on rails 如何使用Mongoid在formtastic中设置单数复选框?,ruby-on-rails,ruby,mongodb,formtastic,Ruby On Rails,Ruby,Mongodb,Formtastic,在我的模型中 field :resizable, type: Boolean, default: true 我在formtastic中尝试过的东西: = f.input :resizable, :as => :check_boxes # This produces two textboxes = f.input :resizable # This produces an input field = f.input :resizable, :as => :check_box # Th
field :resizable, type: Boolean, default: true
我在formtastic中尝试过的东西:
= f.input :resizable, :as => :check_boxes # This produces two textboxes
= f.input :resizable # This produces an input field
= f.input :resizable, :as => :check_box # This produces an error
我作为::复选框出现的错误是:
ActionView::Template::Error (Formtastic::UnknownInputError):
当我使用as::radio时,它可以工作。我不认为:复选框不是一个formtastic输入。此外,从我所看到的情况来看,您的表单没有绑定到模型
只需删除:as参数,就可以设置
遵循Ryan Bates的银幕演员阵容中的例子
如果模型有一个布尔字段,则它将作为复选框呈现。当您指定:as参数时,实际上是在覆盖该字段的默认输入类型。请公布错误。嗨,泰勒,用我的错误消息更新。这将产生两个。。我只需要单选按钮,谢谢。单选按钮与复选框不同,功能也不同。更新我的答案,检查它,并让我知道这是否有帮助。是的,这对Ryan有效,因为他使用的是ActiveRecord。我认为这只是formtastic的一个问题,Mongoid不能很好地工作。
<% semantic_form_for @model do |f| %>
<% f.inputs do %>
<%= f.input :name %>
<%= f.input :born_on %>
<%= f.input :category %>
<%= f.input :female %>
<% end %>
<%= f.buttons %>
<% end %>