开发者

Using :collection and :include_blank in Formtastic. How to do it?

I use the superb Formtastic plugin for Ruby on Rails.

Does anybody know how to include a blank (option), when using a custom collection?

When I try:

<%= f.input :organizations, :collection => Orga开发者_开发知识库nization.all(:order => :name), :include_blank => true %>

I get the select box with the collection, but NOT a blank...


What kind of association is :organizations? Does it work if you specify :as => :select?

There's spec coverage for the following belongs_to select, date, time and datetime inputs:

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? If it's a :has_many or :has_and_belongs_to_many association, Formtastic will try to do checkboxes or a multi-select. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜