Applied the dblack patch

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@499 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 d071deee
......@@ -137,6 +137,9 @@ class InstanceTag #:nodoc:
def initialize(object_name, method_name, template_object, local_binding = nil)
@object_name, @method_name = object_name, method_name
@template_object, @local_binding = template_object, local_binding
if @object_name.sub!(/\[\]$/,"")
@auto_index = @template_object.instance_variable_get("@#{Regexp.last_match.pre_match}").id
end
end
def to_input_field_tag(field_type, options = {})
......@@ -214,6 +217,9 @@ def add_default_name_and_id(options)
options['name'] = tag_name_with_index(options["index"]) unless options.has_key? "name"
options['id'] = tag_id_with_index(options["index"]) unless options.has_key? "id"
options.delete("index")
elsif @auto_index
options['name'] = tag_name_with_index(@auto_index) unless options.has_key? "name"
options['id'] = tag_id_with_index(@auto_index) unless options.has_key? "id"
else
options['name'] = tag_name unless options.has_key? "name"
options['id'] = tag_id unless options.has_key? "id"
......
......@@ -18,6 +18,8 @@ def setup
@post = Post.new
def @post.errors() Class.new{ def on(field) field == "author_name" end }.new end
def @post.id; 123; end
@post.title = "Hello World"
@post.author_name = ""
@post.body = "Back to the hill and over it again!"
......@@ -136,4 +138,28 @@ def test_explicit_id
check_box("post", "secret", "id" => "i mean it")
)
end
def test_auto_index
pid = @post.id
assert_equal(
"<input id=\"post_#{pid}_title\" name=\"post[#{pid}][title]\" size=\"30\" type=\"text\" value=\"Hello World\" />", text_field("post[]","title")
)
assert_equal(
"<textarea cols=\"40\" id=\"post_#{pid}_body\" name=\"post[#{pid}][body]\" rows=\"20\" wrap=\"virtual\">Back to the hill and over it again!</textarea>",
text_area("post[]", "body")
)
assert_equal(
"<input checked=\"checked\" id=\"post_#{pid}_secret\" name=\"post[#{pid}][secret]\" type=\"checkbox\" value=\"1\" /><input name=\"post[#{pid}][secret]\" type=\"hidden\" value=\"0\" />",
check_box("post[]", "secret")
)
assert_equal(
"<input checked=\"checked\" id=\"post_#{pid}_title\" name=\"post[#{pid}][title]\" size=\"30\" type=\"radio\" value=\"Hello World\" />",
radio_button("post[]", "title", "Hello World")
)
assert_equal("<input id=\"post_#{pid}_title\" name=\"post[#{pid}][title]\" size=\"30\" type=\"radio\" value=\"Goodbye World\" />",
radio_button("post[]", "title", "Goodbye World")
)
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册