如果我有以下表格声明:
<%= form_for(@thing, {foo: 'bar', builder: AwesomeBuilder}) do |f|
...
<% end %>
有没有办法可以在AwesomeBuilder的声明中访问表单的选项哈希?我正在尝试像:
class AwesomeBuilder < ActionView::Helpers::FormBuilder
def text_field(method, options={})
options.reverse_merge!(form_for_options[foo])
@template.content_tag(:div, super)
end
end
答案 0 :(得分:1)
尝试:
class AwesomeBuilder < ActionView::Helpers::FormBuilder
def text_field(method, options={})
options.reverse_merge!(self.options[:foo])
@template.content_tag(:div, super)
end
end