[英]Using :collection and :include_blank in Formtastic. How to do it?
我为 Ruby on Rails 使用了极好的 Formtastic 插件。
有谁知道在使用自定义集合时如何包含一个空白(选项)?
当我尝试:
<%= f.input :organizations, :collection => Organization.all(:order => :name), :include_blank => true %>
我得到了带有集合的选择框,但不是空白...
什么样的协会是:organizations
? 如果您指定: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)
我的猜测是组织不是belongs_to
协会,对吗? 如果是:has_many
或:has_and_belongs_to_many
关联,Formtastic 将尝试执行复选框或多选。 在多选的情况下,显然在那里有一个空行是没有意义的(你只是不选择任何项目)。
希望这会有所帮助,请发布有关相关模型和关联的更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.