Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Check if the options hash already exists and merge it with the another

hash.

Closes #2492 and #5614
  • Loading branch information...
commit 6968bc16a1a609c56cf056cd9cd8f8de251defde 1 parent 7111133
Rafael Mendonça França rafaelfranca authored
15 actionpack/lib/action_view/helpers/form_helper.rb
View
@@ -656,15 +656,16 @@ def fields_for(record_name, record_object = nil, options = {}, &block)
# 'Accept <a href="/terms">Terms</a>.'.html_safe
# end
def label(object_name, method, content_or_options = nil, options = nil, &block)
+ options ||= {}
+
content_is_options = content_or_options.is_a?(Hash)
if content_is_options || block_given?
- options = content_or_options if content_is_options
+ options.merge!(content_or_options) if content_is_options
text = nil
else
text = content_or_options
end
- options ||= {}
InstanceTag.new(object_name, method, self, options.delete(:object)).to_label_tag(text, options, &block)
end
@@ -1310,14 +1311,8 @@ def fields_for(record_name, record_object = nil, fields_options = {}, &block)
@template.fields_for(record_name, record_object, fields_options, &block)
end
- def label(method, content_or_options = nil, options = {}, &block)
- if content_or_options.is_a?(Hash)
- content_or_options = objectify_options(content_or_options)
- else
- options = objectify_options(options)
- end
-
- @template.label(@object_name, method, content_or_options, options, &block)
+ def label(method, text = nil, options = {}, &block)
+ @template.label(@object_name, method, text, objectify_options(options), &block)
end
def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
25 actionpack/test/template/form_helper_test.rb
View
@@ -943,10 +943,25 @@ def test_form_for_with_nil_index_option_override
assert_dom_equal expected, output_buffer
end
+ def test_form_for_label_error_wrapping
+ form_for(@post) do |f|
+ concat f.label(:author_name, :class => 'label')
+ concat f.text_field(:author_name)
+ concat f.submit('Create post')
+ end
+
+ expected = whole_form("/posts/123", "edit_post_123" , "edit_post", :method => "put") do
+ "<div class='field_with_errors'><label for='post_author_name' class='label'>Author name</label></div>" +
+ "<div class='field_with_errors'><input name='post[author_name]' size='30' type='text' id='post_author_name' value='' /></div>" +
+ "<input name='commit' type='submit' value='Create post' />"
+ end
+
+ assert_dom_equal expected, output_buffer
+ end
+
+
def test_form_for_label_error_wrapping_without_conventional_instance_variable
post = remove_instance_variable :@post
- default_field_error_proc = ActionView::Base.field_error_proc
- ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| "<div class='error'>#{html_tag}</div>".html_safe }
form_for(post) do |f|
concat f.label(:author_name, :class => 'label')
@@ -955,14 +970,12 @@ def test_form_for_label_error_wrapping_without_conventional_instance_variable
end
expected = whole_form("/posts/123", "edit_post_123" , "edit_post", :method => "put") do
- "<div class='error'><label for='post_author_name' class='label'>Author name</label></div>" +
- "<div class='error'><input name='post[author_name]' size='30' type='text' id='post_author_name' value='' /></div>" +
+ "<div class='field_with_errors'><label for='post_author_name' class='label'>Author name</label></div>" +
+ "<div class='field_with_errors'><input name='post[author_name]' size='30' type='text' id='post_author_name' value='' /></div>" +
"<input name='commit' type='submit' value='Create post' />"
end
assert_dom_equal expected, output_buffer
- ensure
- ActionView::Base.field_error_proc = default_field_error_proc
end
def test_form_for_with_namespace
Please sign in to comment.
Something went wrong with that request. Please try again.