Rails include_blank with content_tag并选择

时间:2016-07-21 16:54:17

标签: ruby-on-rails

我创建了一个构建器对象,用于创建选择元素。它看起来像这样:

module FormHelper
  def list_filter(field, label, sources, options = {})
    Filter.new(field, label, sources, options.merge(template: self)).render
  end
end  

class Filter
  attr_accessor :field, :label, :sources, :template

  def initialize(field, label, sources, options = {})
    @label = label
    @field = field
    @sources = sources
    assign_attributes(options)
  end

  def options_for_select
    template.send(:options_for_select,[['abc',1],['def',2],['ghi',3]], template.params[name])
  end

  def html_options
    attrs = {}
    attrs['class'] = 'abc'
    attrs['name'] = field
    attrs
  end

  def render
    template.content_tag(:select, options_for_select, html_options )
  end
end

我的问题是当content_tagselect一起使用时,我如何使用include_blankprompt选项?

这样的事情不起作用:

template.content_tag(:select, options_for_select, { include_blank: true }.merge(html_attributes) )

0 个答案:

没有答案