Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何使用Mongoid在formtastic中设置单数复选框?_Ruby On Rails_Ruby_Mongodb_Formtastic - Fatal编程技术网

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 %>