简体   繁体   English

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

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

相关问题 Formtastic - :include_blank 选项的自定义返回值 - Formtastic - custom return value for :include_blank option 使用rails collection_select表单助手更改&#39;include_blank&#39;文本的样式 - Changing the style of the 'include_blank' text using a rails collection_select form helper collection_select将:include_blank的选项值设置为零 - collection_select set option value of :include_blank to zero ROR:带有include_blank的选择集合不允许为零 - ROR: Collection select with with include_blank won't allow nil Rails collection_select为include_blank设置值 - Rails collection_select set value for include_blank 在f.select中使用include_blank但不起作用 - using include_blank in f.select but not working Formtastic。 如何为同一模型的多个对象创建表单? - Formtastic. How to create a form for multiple objects of the same model? 在常规提示之外,在Rails collection_select中包含自定义ID和值:或:include_blank? - Include custom id and value in Rails collection_select besides the normal prompt: or :include_blank? 使用formtastic进行拆分和排列。 错误:未定义的方法“地图” - Splitting and array using formtastic. Error: undefined method `map' 我可以在rails上使用带有include_blank的option_groups_from_collection_for_select吗? - Can I use option_groups_from_collection_for_select with include_blank on rails?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM