Skip to content

Instantly share code, notes, and snippets.

@samuelkadolph
Created December 1, 2010 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuelkadolph/724268 to your computer and use it in GitHub Desktop.
Save samuelkadolph/724268 to your computer and use it in GitHub Desktop.
Simple example showing how to safely add a method to ActionView::Helpers::FormBuilder
module FormHelper
class CustomFormBuilder < ActionView::Helpers::FormBuilder
def autocomplete_field(method, url, options = {})
text_field(method, options.reverse_merge(:'data-autocomplete' => url)
end
end
%w(form_for fields_for).each do |method|
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
def omega_#{method}(record_or_name_or_array, *args, &proc)
options = args.extract_options!
options[:builder] = CustomFormBuilder
#{method}(record_or_name_or_array, *(args << options), &proc)
end
RUBY_EVAL
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment