Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #3772 from lest/label-with-block

fix label with block in erb
  • Loading branch information...
commit ee8db25e64df7fa5870781957dcdc67fa2a1d8e1 2 parents 3c81fc3 + bc81ba2
@josevalim josevalim authored
View
4 actionpack/lib/action_view/helpers/form_helper.rb
@@ -960,7 +960,7 @@ def instantiate_builder(record_name, record_object, options, &block)
end
class InstanceTag
- include Helpers::CaptureHelper, Context, Helpers::TagHelper, Helpers::FormTagHelper
+ include Helpers::TagHelper, Helpers::FormTagHelper
attr_reader :object, :method_name, :object_name
@@ -992,7 +992,7 @@ def to_label_tag(text = nil, options = {}, &block)
options["for"] ||= name_and_id["id"]
if block_given?
- label_tag(name_and_id["id"], options, &block)
+ @template_object.label_tag(name_and_id["id"], options, &block)
else
content = if text.blank?
object_name.gsub!(/\[(.*)_attributes\]\[\d\]/, '.\1')
View
4 actionpack/test/fixtures/test/_label_with_block.erb
@@ -0,0 +1,4 @@
+<%= label 'post', 'message' do %>
+ Message
+ <%= text_field 'post', 'message' %>
+<% end %>
View
7 actionpack/test/template/form_helper_test.rb
@@ -230,6 +230,13 @@ def test_label_with_block
assert_dom_equal('<label for="post_title">The title, please:</label>', label(:post, :title) { "The title, please:" })
end
+ def test_label_with_block_in_erb
+ path = ActionView::FileSystemResolver.new(FIXTURE_LOAD_PATH)
+ view_paths = ActionView::PathSet.new([path])
+ view = ActionView::Base.new(view_paths)
+ assert_equal "<label for=\"post_message\">\n Message\n <input id=\"post_message\" name=\"post[message]\" size=\"30\" type=\"text\" />\n</label>", view.render("test/label_with_block")
+ end
+
def test_text_field
assert_dom_equal(
'<input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />', text_field("post", "title")
Please sign in to comment.
Something went wrong with that request. Please try again.