如何在表单构建器中访问rails form_for选项?

时间:2013-09-25 16:34:56

标签: ruby-on-rails ruby actionview formbuilder

如果我有以下表格声明:

<%= 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

1 个答案:

答案 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