gpt4 book ai didi

ruby-on-rails - 使用:collection and :include_blank in Formtastic. 怎么办?

转载 作者:行者123 更新时间:2023-12-02 04:10:31 25 4
gpt4 key购买 nike

我使用 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 将尝试进行复选框或多选。在多选的情况下,显然在那里有一个空行是没有意义的(您只是不选择任何项目)。

希望这有帮助,请发布有关相关模型和关联的更多详细信息。

关于ruby-on-rails - 使用:collection and :include_blank in Formtastic. 怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2110347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com