繁体   English   中英

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

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM