在Formtastic中使用:collection和:include_blank.怎么做?

Den*_*nis 13 ruby-on-rails formtastic

我使用Ruby on Rails的精湛的Formtastic插件.

在使用自定义集合时,有人知道如何包含空格(选项)吗?

当我尝试:

<%= f.input :organizations, :collection => Organization.all(:order => :name), :include_blank => true %>
Run Code Online (Sandbox Code Playgroud)

我得到了收藏的选择框,但不是空白...

Jus*_*nch 22

什么样的协会是:组织?如果指定:as =>:select,它是否有效?

以下belongs_to选择,日期,时间和日期时间输入的规范覆盖范围:

f.input(:author, :as => :select, :include_blank => true)
f.input(:created_at, :as => :date, :include_blank => true)
f.input(:created_at, :as => :time, :include_blank => true)
f.input(:created_at, :as => :datetime, :include_blank => true)
Run Code Online (Sandbox Code Playgroud)

我的猜测是组织不是belongs_to协会,对吧?如果它是:has_many或:has_and_belongs_to_many关联,Formtastic将尝试执行复选框或多选.在多选的情况下,显然在那里有一个空行是没有意义的(你只是不选择任何项目).

希望这有帮助,请发布有关模型和协会的更多详细信息.