【问题标题】:option_groups_from_collection_for_select with include_blank optionoption_groups_from_collection_for_select 和 include_blank 选项
【发布时间】:2016-08-06 04:39:40
【问题描述】:

我在这里尝试为“option_groups_from_collection_for_select”包含一个 include_blank 选项时遇到了一些麻烦 我想要 include_blank 选项,但在更新操作时显示当前选择的值而不是空白选择。我在这里尝试过,但它仍然显示为空白。

    select_tag(:candidate_source, option_groups_from_collection_for_select(grouped_candidate_sources, :second, :first, :id, :source), { :include_blank => true, :selected => :source }) 

【问题讨论】:

    标签: ruby-on-rails-3


    【解决方案1】:

    option_groups_from_collection_for_select 中的最后一个参数是选定的选项,它应该映射到您的值。

    由于您的option_key_method(第4 个参数)是:id,因此您可以直接将表单对象作为参数传递。示例:

    select_tag(:candidate_source, option_groups_from_collection_for_select(grouped_candidate_sources, :second, :first, :id, :source, f.object.source), { :include_blank => true }
    

    无论如何,请参阅此处了解更多参数信息:http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/option_groups_from_collection_for_select

    【讨论】:

      猜你喜欢
      • 2011-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-03
      • 2016-11-26
      • 1970-01-01
      相关资源
      最近更新 更多