Question

If I've got a form declaration like the following:

<%= form_for(@thing, {foo: 'bar', builder: AwesomeBuilder}) do |f| 
  ...
<% end %>

Is there any way I can access the form's option hash in the declaration for AwesomeBuilder? I'm trying to Something like:

class AwesomeBuilder < ActionView::Helpers::FormBuilder
  def text_field(method, options={})
    options.reverse_merge!(form_for_options[foo])
    @template.content_tag(:div, super)
  end
end
Was it helpful?

Solution

Try:

class AwesomeBuilder < ActionView::Helpers::FormBuilder
  def text_field(method, options={})
    options.reverse_merge!(self.options[:foo])
    @template.content_tag(:div, super)
  end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top