Skip to content
Browse files

Add support to Rails 3.1.0. Closes #252

  • Loading branch information...
1 parent e45918b commit d529379c72b87ebcd2e1bd7182b47305982eec55 @rafaelfranca rafaelfranca committed Jun 25, 2011
Showing with 33 additions and 20 deletions.
  1. +24 −20 lib/simple_form/action_view_extensions/form_helper.rb
  2. +9 −0 test/support/mock_controller.rb
View
44 lib/simple_form/action_view_extensions/form_helper.rb
@@ -29,27 +29,31 @@ def with_custom_field_error_proc(&block)
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
View
9 test/support/mock_controller.rb
@@ -12,4 +12,13 @@ def action_name
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

0 comments on commit d529379

Please sign in to comment.
Something went wrong with that request. Please try again.