public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fixed form helper's name attribute for question methods
avit (author)
Mon May 05 12:45:09 -0700 2008
rick (committer)
Tue May 06 00:03:32 -0700 2008
commit  04f52219f11944e50555dc59917c73c99581dac0
tree    4f6ebcdc370ac5de6aba10c376630d2237af0c72
parent  123e55686de920499cc8572f3a8b4d585d20ab02
...
614
615
616
617
 
618
619
620
621
 
622
623
624
625
 
626
627
628
629
 
630
631
632
633
 
 
 
 
 
634
635
636
...
614
615
616
 
617
618
619
620
 
621
622
623
624
 
625
626
627
628
 
629
630
631
632
 
633
634
635
636
637
638
639
640
0
@@ -614,23 +614,27 @@ module ActionView
0
         end
0
 
0
         def tag_name
0
-          "#{@object_name}[#{@method_name}]"
0
+          "#{@object_name}[#{sanitized_method_name}]"
0
         end
0
 
0
         def tag_name_with_index(index)
0
-          "#{@object_name}[#{index}][#{@method_name}]"
0
+          "#{@object_name}[#{index}][#{sanitized_method_name}]"
0
         end
0
 
0
         def tag_id
0
-          "#{sanitized_object_name}_#{@method_name}"
0
+          "#{sanitized_object_name}_#{sanitized_method_name}"
0
         end
0
 
0
         def tag_id_with_index(index)
0
-          "#{sanitized_object_name}_#{index}_#{@method_name}"
0
+          "#{sanitized_object_name}_#{index}_#{sanitized_method_name}"
0
         end
0
 
0
         def sanitized_object_name
0
-          @object_name.gsub(/[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
0
+          @sanitized_object_name ||= @object_name.gsub(/[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
0
+        end
0
+
0
+        def sanitized_method_name
0
+          @sanitized_method_name ||= @method_name.sub(/\?$/,"")
0
         end
0
     end
0
 
...
6
7
8
 
9
10
11
...
71
72
73
 
74
75
76
77
 
78
79
80
...
140
141
142
 
 
143
144
145
...
172
173
174
 
 
 
 
175
176
177
...
6
7
8
9
10
11
12
...
72
73
74
75
76
77
78
79
80
81
82
83
...
143
144
145
146
147
148
149
150
...
177
178
179
180
181
182
183
184
185
186
0
@@ -6,6 +6,7 @@ silence_warnings do
0
     alias_method :title_before_type_cast, :title unless respond_to?(:title_before_type_cast)
0
     alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast)
0
     alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast)
0
+    alias_method :secret?, :secret 
0
 
0
     def new_record=(boolean)
0
       @new_record = boolean
0
@@ -71,10 +72,12 @@ class FormHelperTest < ActionView::TestCase
0
       '<label class="title_label" for="post_title">Title</label>',
0
       label("post", "title", nil, :class => 'title_label')
0
     )
0
+    assert_dom_equal('<label for="post_secret">Secret?</label>', label("post", "secret?"))
0
   end
0
 
0
   def test_label_with_symbols
0
     assert_dom_equal('<label for="post_title">Title</label>', label(:post, :title))
0
+    assert_dom_equal('<label for="post_secret">Secret?</label>', label(:post, :secret?))
0
   end
0
 
0
   def test_label_with_for_attribute_as_symbol
0
@@ -140,6 +143,8 @@ class FormHelperTest < ActionView::TestCase
0
   def test_hidden_field
0
     assert_dom_equal '<input id="post_title" name="post[title]" type="hidden" value="Hello World" />',
0
       hidden_field("post", "title")
0
+      assert_dom_equal '<input id="post_secret" name="post[secret]" type="hidden" value="1" />',
0
+        hidden_field("post", "secret?")
0
   end
0
 
0
   def test_hidden_field_with_escapes
0
@@ -172,6 +177,10 @@ class FormHelperTest < ActionView::TestCase
0
       '<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
0
       check_box("post", "secret")
0
     )
0
+    assert_dom_equal(
0
+      '<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
0
+      check_box("post", "secret?")
0
+    )
0
   end
0
 
0
   def test_check_box_with_explicit_checked_and_unchecked_values

Comments