簡體   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