Created
December 1, 2010 21:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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