我创建了一个构建器对象,用于创建选择元素。它看起来像这样:
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_tag
与select
一起使用时,我如何使用include_blank
或prompt
选项?
这样的事情不起作用:
template.content_tag(:select, options_for_select, { include_blank: true }.merge(html_attributes) )