Make form helper method definitions a little bit more dynamic.

This commit is contained in:
José Valim 2009-12-10 12:26:40 -02:00
parent 7fe0379113
commit c9052a90c4
2 changed files with 9 additions and 19 deletions

View File

@ -6,7 +6,7 @@
* Get default string options from column definition
* Add support to default :prompt methods on datetime inputs
* Add support to default label method
* Add support to label, error and hint calls
* Add support to f.label, f.error and f.hint calls
* Improve readme with examples
* :country, :time_zone, :group and :file types support

View File

@ -1,25 +1,15 @@
module SimpleForm
module ActionViewExtensions
module FormHelper
def simple_form_for(*args, &block)
build_simple_form(:form_for, *args, &block)
[:form_for, :fields_for, :remote_form_for].each do |helper|
class_eval <<-METHOD, __FILE__, __LINE__
def simple_#{helper}(*args, &block)
options = args.extract_options!
options[:builder] = SimpleForm::FormBuilder
#{helper}(*(args << options), &block)
end
METHOD
end
def simple_fields_for(*args, &block)
build_simple_form(:fields_for, *args, &block)
end
def simple_remote_form_for(*args, &block)
build_simple_form(:remote_form_for, *args, &block)
end
private
def build_simple_form(form_method, *args, &block)
options = args.extract_options!
options[:builder] = SimpleForm::FormBuilder
send(form_method, *(args << options), &block)
end
end
end
end