[英]Using :collection and :include_blank in Formtastic. How to do it?
I use the superb Formtastic plugin for Ruby on Rails.我为 Ruby on Rails 使用了极好的 Formtastic 插件。
Does anybody know how to include a blank (option), when using a custom collection?有谁知道在使用自定义集合时如何包含一个空白(选项)?
When I try:当我尝试:
<%= f.input :organizations, :collection => Organization.all(:order => :name), :include_blank => true %>
I get the select box with the collection, but NOT a blank...我得到了带有集合的选择框,但不是空白...
What kind of association is :organizations
?什么样的协会是
:organizations
? Does it work if you specify :as => :select
?如果您指定
:as => :select
是否有效?
There's spec coverage for the following belongs_to
select, date, time and datetime inputs:以下
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)
My guess is that organizations is not a belongs_to
association, right?我的猜测是组织不是
belongs_to
协会,对吗? If it's a :has_many
or :has_and_belongs_to_many
association, Formtastic will try to do checkboxes or a multi-select.如果是
:has_many
或:has_and_belongs_to_many
关联,Formtastic 将尝试执行复选框或多选。 In the case of a multi-select, obviously it makes no sense to have a blank line in there (you just don't select any of the items).在多选的情况下,显然在那里有一个空行是没有意义的(你只是不选择任何项目)。
Hope this helps, please post some more details about the models and associations in question.希望这会有所帮助,请发布有关相关模型和关联的更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.