diff --git a/lib/simple_form/action_view_extensions/form_helper.rb b/lib/simple_form/action_view_extensions/form_helper.rb index 211c3e05..b6f4f2da 100644 --- a/lib/simple_form/action_view_extensions/form_helper.rb +++ b/lib/simple_form/action_view_extensions/form_helper.rb @@ -29,27 +29,31 @@ module SimpleForm result end - [:form_for, :fields_for].each do |helper| - class_eval <<-METHOD, __FILE__, __LINE__ - def simple_#{helper}(record_or_name_or_array, *args, &block) - options = args.extract_options! - options[:builder] ||= SimpleForm::FormBuilder - css_class = case record_or_name_or_array - when String, Symbol then record_or_name_or_array.to_s - when Array then dom_class(record_or_name_or_array.last) - else dom_class(record_or_name_or_array) - end - options[:html] ||= {} - unless options[:html].key?(:novalidate) - options[:html][:novalidate] = !SimpleForm.browser_validations - end - options[:html][:class] = "\#{SimpleForm.form_class} \#{css_class} \#{options[:html][:class]}".strip + def simple_form_for(record, options={}, &block) + options[:builder] ||= SimpleForm::FormBuilder + css_class = case record + when String, Symbol then record.to_s + when Array then dom_class(record.last) + else dom_class(record) + end + options[:html] ||= {} + unless options[:html].key?(:novalidate) + options[:html][:novalidate] = !SimpleForm.browser_validations + end + options[:html][:class] = "#{SimpleForm.form_class} #{css_class} #{options[:html][:class]}".strip - with_custom_field_error_proc do - #{helper}(record_or_name_or_array, *(args << options), &block) - end - end - METHOD + with_custom_field_error_proc do + form_for(record, options, &block) + end + end + + def simple_fields_for(record_name, record_object = nil, options = {}, &block) + options, record_object = record_object, nil if record_object.is_a?(Hash) + options[:builder] ||= SimpleForm::FormBuilder + + with_custom_field_error_proc do + fields_for(record_name, record_object, options, &block) + end end end end diff --git a/test/support/mock_controller.rb b/test/support/mock_controller.rb index 30f7fc0e..ed608795 100644 --- a/test/support/mock_controller.rb +++ b/test/support/mock_controller.rb @@ -12,4 +12,13 @@ class MockController def url_for(*args) "http://example.com" end + + def url_helpers + self + end + + def hash_for_user_path(*args); end + def hash_for_validating_user_path(*args); end + def hash_for_other_validating_user_path(*args); end + def hash_for_users_path(*args); end end