actionpack 0.9.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

Files changed (53) hide show
  1. data/CHANGELOG +177 -0
  2. data/README +0 -1
  3. data/install.rb +1 -0
  4. data/lib/action_controller.rb +6 -1
  5. data/lib/action_controller/assertions/active_record_assertions.rb +2 -2
  6. data/lib/action_controller/base.rb +53 -41
  7. data/lib/action_controller/benchmarking.rb +1 -1
  8. data/lib/action_controller/cgi_ext/cgi_methods.rb +14 -16
  9. data/lib/action_controller/cgi_process.rb +16 -6
  10. data/lib/action_controller/cookies.rb +70 -0
  11. data/lib/action_controller/dependencies.rb +106 -0
  12. data/lib/action_controller/helpers.rb +14 -3
  13. data/lib/action_controller/layout.rb +16 -2
  14. data/lib/action_controller/request.rb +17 -7
  15. data/lib/action_controller/rescue.rb +33 -3
  16. data/lib/action_controller/support/class_inheritable_attributes.rb +4 -0
  17. data/lib/action_controller/support/inflector.rb +14 -12
  18. data/lib/action_controller/support/misc.rb +6 -0
  19. data/lib/action_controller/templates/rescues/_request_and_response.rhtml +2 -2
  20. data/lib/action_controller/templates/rescues/diagnostics.rhtml +4 -6
  21. data/lib/action_controller/templates/rescues/template_error.rhtml +1 -9
  22. data/lib/action_controller/templates/scaffolds/edit.rhtml +2 -1
  23. data/lib/action_controller/templates/scaffolds/layout.rhtml +36 -0
  24. data/lib/action_controller/templates/scaffolds/new.rhtml +1 -0
  25. data/lib/action_controller/test_process.rb +27 -8
  26. data/lib/action_controller/url_rewriter.rb +15 -4
  27. data/lib/action_view/base.rb +4 -3
  28. data/lib/action_view/helpers/active_record_helper.rb +29 -15
  29. data/lib/action_view/helpers/date_helper.rb +6 -5
  30. data/lib/action_view/helpers/form_helper.rb +31 -4
  31. data/lib/action_view/helpers/form_options_helper.rb +13 -3
  32. data/lib/action_view/helpers/tag_helper.rb +14 -16
  33. data/lib/action_view/helpers/url_helper.rb +46 -1
  34. data/lib/action_view/partials.rb +8 -1
  35. data/lib/action_view/template_error.rb +10 -3
  36. data/lib/action_view/vendor/builder/blankslate.rb +33 -1
  37. data/lib/action_view/vendor/builder/xmlevents.rb +1 -1
  38. data/lib/action_view/vendor/builder/xmlmarkup.rb +1 -1
  39. data/rakefile +4 -13
  40. data/test/controller/action_pack_assertions_test.rb +39 -1
  41. data/test/controller/active_record_assertions_test.rb +6 -5
  42. data/test/controller/cgi_test.rb +33 -3
  43. data/test/controller/cookie_test.rb +43 -2
  44. data/test/controller/helper_test.rb +1 -1
  45. data/test/controller/render_test.rb +9 -0
  46. data/test/controller/url_test.rb +16 -0
  47. data/test/fixtures/scope/test/modgreet.rhtml +1 -0
  48. data/test/template/active_record_helper_test.rb +34 -8
  49. data/test/template/date_helper_test.rb +164 -20
  50. data/test/template/form_helper_test.rb +12 -0
  51. data/test/template/form_options_helper_test.rb +7 -16
  52. data/test/template/url_helper_test.rb +12 -0
  53. metadata +8 -2
@@ -28,6 +28,10 @@ module ClassInheritableAttributes # :nodoc:
28
28
  inheritable_attributes[key]
29
29
  end
30
30
 
31
+ def reset_inheritable_attributes
32
+ inheritable_attributes.clear
33
+ end
34
+
31
35
  private
32
36
  def inherited(child)
33
37
  @@classes[child] = inheritable_attributes.dup
@@ -48,6 +48,7 @@ module Inflector
48
48
  def plural_rules #:doc:
49
49
  [
50
50
  [/(x|ch|ss)$/, '\1es'], # search, switch, fix, box, process, address
51
+ [/([^aeiouy]|qu)ies$/, '\1y'],
51
52
  [/([^aeiouy]|qu)y$/, '\1ies'], # query, ability, agency
52
53
  [/(?:([^f])fe|([lr])f)$/, '\1\2ves'], # half, safe, wife
53
54
  [/sis$/, 'ses'], # basis, diagnosis
@@ -62,17 +63,18 @@ module Inflector
62
63
 
63
64
  def singular_rules #:doc:
64
65
  [
65
- [/(x|ch|ss)es$/, '\1'],
66
- [/([^aeiouy]|qu)ies$/, '\1y'],
67
- [/([lr])ves$/, '\1f'],
68
- [/([^f])ves$/, '\1fe'],
69
- [/(analy|ba|diagno|parenthe|progno|synop|the)ses$/, '\1sis'],
70
- [/([ti])a$/, '\1um'],
71
- [/people$/, 'person'],
72
- [/men$/, 'man'],
73
- [/status$/, 'status'],
74
- [/children$/, 'child'],
75
- [/s$/, '']
76
- ]
66
+ [/(x|ch|ss)es$/, '\1'],
67
+ [/movies$/, 'movie'],
68
+ [/([^aeiouy]|qu)ies$/, '\1y'],
69
+ [/([lr])ves$/, '\1f'],
70
+ [/([^f])ves$/, '\1fe'],
71
+ [/(analy|ba|diagno|parenthe|progno|synop|the)ses$/, '\1sis'],
72
+ [/([ti])a$/, '\1um'],
73
+ [/people$/, 'person'],
74
+ [/men$/, 'man'],
75
+ [/status$/, 'status'],
76
+ [/children$/, 'child'],
77
+ [/s$/, '']
78
+ ]
77
79
  end
78
80
  end
@@ -0,0 +1,6 @@
1
+ def silence_warnings
2
+ old_verbose, $VERBOSE = $VERBOSE, nil
3
+ result = yield
4
+ $VERBOSE = old_verbose
5
+ return result
6
+ end
@@ -1,6 +1,6 @@
1
+ <% if defined?(Breakpoint) then %><a href="?BP-RETRY=1">Retry with Breakpoint</a><% end %>
2
+
1
3
  <%
2
- base_dir = File.expand_path(File.dirname(__FILE__))
3
-
4
4
  request_parameters_without_action = @request.parameters.clone
5
5
  request_parameters_without_action.delete("action")
6
6
  request_parameters_without_action.delete("controller")
@@ -1,8 +1,6 @@
1
1
  <%
2
- base_dir = File.expand_path(File.dirname(__FILE__))
3
-
4
- clean_backtrace = @exception.backtrace.collect { |line| line.gsub(base_dir, "").gsub("/../config/environments/../../", "") }
5
- app_trace = clean_backtrace.reject { |line| line[0..6] == "vendor/" || line.include?("dispatch.cgi") }
2
+ clean_backtrace = @exception.backtrace.collect { |line| Object.const_defined?(:RAILS_ROOT) ? line.gsub(RAILS_ROOT, "") : line }
3
+ app_trace = clean_backtrace.reject { |line| line =~ /(vendor|dispatch|ruby)/ }
6
4
  framework_trace = clean_backtrace - app_trace
7
5
  %>
8
6
 
@@ -10,9 +8,9 @@
10
8
  <%=h @exception.class.to_s %> in
11
9
  <%=h @request.parameters["controller"].capitalize %>#<%=h @request.parameters["action"] %>
12
10
  </h1>
13
- <p><%=h @exception.message %></p>
11
+ <p><%=h Object.const_defined?(:RAILS_ROOT) ? @exception.message.gsub(RAILS_ROOT, "") : @exception.message %></p>
14
12
 
15
- <% unless app_trace.empty? %><pre><code><%=h app_trace.collect { |line| line.gsub("/../", "") }.join("\n") %></code></pre><% end %>
13
+ <% unless app_trace.empty? %><pre><code><%=h app_trace.join("\n") %></code></pre><% end %>
16
14
 
17
15
  <% unless framework_trace.empty? %>
18
16
  <a href="#" onclick="document.getElementById('framework_trace').style.display='block'; return false;">Show framework trace</a>
@@ -1,11 +1,3 @@
1
- <%
2
- base_dir = File.expand_path(File.dirname(__FILE__))
3
-
4
- framework_trace = @exception.original_exception.backtrace.collect do |line|
5
- line.gsub(base_dir, "").gsub("/../config/environments/../../", "")
6
- end
7
- %>
8
-
9
1
  <h1>
10
2
  <%=h @exception.original_exception.class.to_s %> in
11
3
  <%=h @request.parameters["controller"].capitalize %>#<%=h @request.parameters["action"] %>
@@ -21,6 +13,6 @@
21
13
  <p><%=h @exception.sub_template_message %></p>
22
14
 
23
15
  <a href="#" onclick="document.getElementById('framework_trace').style.display='block'">Show template trace</a>
24
- <pre id="framework_trace" style="display:none"><code><%=h framework_trace.join("\n") %></code></pre>
16
+ <pre id="framework_trace" style="display:none"><code><%=h @exception.original_exception.backtrace.collect { |line| Object.const_defined?(:RAILS_ROOT) ? line.gsub(RAILS_ROOT, "") : line }.join("\n") %></code></pre>
25
17
 
26
18
  <%= render_file(@rescues_path + "/_request_and_response.rhtml", false) %>
@@ -1,6 +1,7 @@
1
1
  <h1>Editing <%= @scaffold_singular_name %></h1>
2
2
 
3
- <%= form(@scaffold_singular_name, :action => "../update" + @scaffold_suffix) %>
3
+ <%= error_messages_for(@scaffold_singular_name) %>
4
+ <%= form(@scaffold_singular_name, :action => "update" + @scaffold_suffix) %>
4
5
 
5
6
  <%= link_to "Show", :action => "show#{@scaffold_suffix}", :id => instance_variable_get("@#{@scaffold_singular_name}").id %> |
6
7
  <%= link_to "Back", :action => "list#{@scaffold_suffix}" %>
@@ -19,6 +19,42 @@
19
19
  a { color: #000; }
20
20
  a:visited { color: #666; }
21
21
  a:hover { color: #fff; background-color:#000; }
22
+
23
+ .fieldWithErrors {
24
+ padding: 2px;
25
+ background-color: red;
26
+ display: table;
27
+ }
28
+
29
+ #ErrorExplanation {
30
+ width: 400px;
31
+ border: 2px solid #red;
32
+ padding: 7px;
33
+ padding-bottom: 12px;
34
+ margin-bottom: 20px;
35
+ background-color: #f0f0f0;
36
+ }
37
+
38
+ #ErrorExplanation h2 {
39
+ text-align: left;
40
+ font-weight: bold;
41
+ padding: 5px 5px 5px 15px;
42
+ font-size: 12px;
43
+ margin: -7px;
44
+ background-color: #c00;
45
+ color: #fff;
46
+ }
47
+
48
+ #ErrorExplanation p {
49
+ color: #333;
50
+ margin-bottom: 0;
51
+ padding: 5px;
52
+ }
53
+
54
+ #ErrorExplanation ul li {
55
+ font-size: 12px;
56
+ list-style: square;
57
+ }
22
58
  </style>
23
59
  </head>
24
60
  <body>
@@ -1,5 +1,6 @@
1
1
  <h1>New <%= @scaffold_singular_name %></h1>
2
2
 
3
+ <%= error_messages_for(@scaffold_singular_name) %>
3
4
  <%= form(@scaffold_singular_name, :action => "create" + @scaffold_suffix) %>
4
5
 
5
6
  <%= link_to "Back", :action => "list#{@scaffold_suffix}" %>
@@ -177,19 +177,38 @@ end
177
177
  @attributes[key] = value
178
178
  end
179
179
 
180
+ def session_id
181
+ ""
182
+ end
183
+
180
184
  def update() end
181
185
  def close() end
182
186
  def delete() @attributes = {} end
183
187
  end
184
188
  end
185
189
 
186
- class Test::Unit::TestCase #:nodoc:
187
- private
188
- # execute the request and set/volley the response
189
- def process(action, parameters = nil, session = nil)
190
- @request.action = action.to_s
191
- @request.parameters.update(parameters) unless parameters.nil?
192
- @request.session = ActionController::TestSession.new(session) unless session.nil?
193
- @controller.process(@request, @response)
190
+ module Test
191
+ module Unit
192
+ class TestCase #:nodoc:
193
+ private
194
+ # execute the request and set/volley the response
195
+ def process(action, parameters = nil, session = nil)
196
+ @request.env['REQUEST_METHOD'] ||= "GET"
197
+ @request.action = action.to_s
198
+ @request.parameters.update(parameters) unless parameters.nil?
199
+ @request.session = ActionController::TestSession.new(session) unless session.nil?
200
+ @controller.process(@request, @response)
201
+ end
202
+
203
+ # execute the request simulating a specific http method and set/volley the response
204
+ %w( get post put delete head ).each do |method|
205
+ class_eval <<-EOV
206
+ def #{method}(action, parameters = nil, session = nil)
207
+ @request.env['REQUEST_METHOD'] = "#{method.upcase}"
208
+ process(action, parameters, session)
209
+ end
210
+ EOV
211
+ end
194
212
  end
213
+ end
195
214
  end
@@ -1,7 +1,7 @@
1
1
  module ActionController
2
2
  # Rewrites urls for Base.redirect_to and Base.url_for in the controller.
3
3
  class UrlRewriter #:nodoc:
4
- VALID_OPTIONS = [:action, :action_prefix, :action_suffix, :controller, :controller_prefix, :anchor, :params, :path_params, :id, :only_path, :overwrite_params ]
4
+ VALID_OPTIONS = [:action, :action_prefix, :action_suffix, :module, :controller, :controller_prefix, :anchor, :params, :path_params, :id, :only_path, :overwrite_params ]
5
5
 
6
6
  def initialize(request, controller, action)
7
7
  @request, @controller, @action = request, controller, action
@@ -12,7 +12,7 @@ module ActionController
12
12
  validate_options(VALID_OPTIONS, options.keys)
13
13
 
14
14
  rewrite_url(
15
- rewrite_path(@rewritten_path, options),
15
+ rewrite_path(@rewritten_path, resolve_aliases(options)),
16
16
  options
17
17
  )
18
18
  end
@@ -30,8 +30,13 @@ module ActionController
30
30
  unknown_option_keys = supplied_option_keys - valid_option_keys
31
31
  raise(ActionController::ActionControllerError, "Unknown options: #{unknown_option_keys}") unless unknown_option_keys.empty?
32
32
  end
33
+
34
+ def resolve_aliases(options)
35
+ options[:controller_prefix] = options[:module] unless options[:module].nil?
36
+ options
37
+ end
33
38
 
34
- def rewrite_url(path, options)
39
+ def rewrite_url(path, options)
35
40
  rewritten_url = ""
36
41
  rewritten_url << @request.protocol unless options[:only_path]
37
42
  rewritten_url << @request.host_with_port unless options[:only_path]
@@ -123,7 +128,13 @@ module ActionController
123
128
 
124
129
  def controller_name(options, controller_prefix)
125
130
  ensure_slash_suffix(options, :controller_prefix)
126
- controller_name = options[:controller_prefix] || controller_prefix || ""
131
+
132
+ controller_name = case options[:controller_prefix]
133
+ when String: options[:controller_prefix]
134
+ when false : ""
135
+ when nil : controller_prefix || ""
136
+ end
137
+
127
138
  controller_name << (options[:controller] + "/") if options[:controller]
128
139
  return controller_name
129
140
  end
@@ -141,7 +141,7 @@ module ActionView #:nodoc:
141
141
  end
142
142
  end
143
143
 
144
- def self.controller_delegate(*methods)
144
+ def self.controller_delegate(*methods)#:nodoc:
145
145
  methods.flatten.each do |method|
146
146
  class_eval <<-end_eval
147
147
  def #{method}(*args, &block)
@@ -238,7 +238,8 @@ module ActionView #:nodoc:
238
238
  end
239
239
 
240
240
  def template_exists?(template_path, extension)
241
- FileTest.exists?(full_template_path(template_path, extension))
241
+ (cache_template_loading && @@loaded_templates.has_key?(template_path)) ||
242
+ FileTest.exists?(full_template_path(template_path, extension))
242
243
  end
243
244
 
244
245
  def read_template_file(template_path)
@@ -250,7 +251,7 @@ module ActionView #:nodoc:
250
251
  end
251
252
 
252
253
  def rhtml_render(template, binding)
253
- @@compiled_erb_templates[template] ||= ERB.new(template)
254
+ @@compiled_erb_templates[template] ||= ERB.new(template, nil, '-')
254
255
  @@compiled_erb_templates[template].result(binding)
255
256
  end
256
257
 
@@ -24,7 +24,7 @@ module ActionView
24
24
  # Returns an entire form with input tags and everything for a specified Active Record object. Example
25
25
  # (post is a new record that has a title using VARCHAR and a body using TEXT):
26
26
  # form("post") =>
27
- # <form action='create' method='POST'>
27
+ # <form action='/post/create' method='post'>
28
28
  # <p>
29
29
  # <label for="post_title">Title</label><br />
30
30
  # <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />
@@ -44,20 +44,24 @@ module ActionView
44
44
  # form("entry", :action => "sign", :input_block =>
45
45
  # Proc.new { |record, column| "#{column.human_name}: #{input(record, column.name)}<br />" }) =>
46
46
  #
47
- # <form action='sign' method='POST'>
47
+ # <form action='/post/sign' method='post'>
48
48
  # Message:
49
49
  # <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /><br />
50
50
  # <input type='submit' value='Sign' />
51
51
  # </form>
52
52
  def form(record_name, options = {})
53
53
  record = instance_eval("@#{record_name}")
54
- action = options[:action] || (record.new_record? ? "create" : "update")
55
- id_field = record.new_record? ? "" : InstanceTag.new(record_name, "id", self).to_input_field_tag("hidden")
56
54
 
57
- "<form action='#{action}' method='POST'>" +
58
- id_field + all_input_tags(record, record_name, options) +
59
- "<input type='submit' value='#{action.gsub(/[^A-Za-z]/, "").capitalize}' />" +
60
- "</form>"
55
+ options[:action] ||= record.new_record? ? "create" : "update"
56
+ action = url_for(:action => options[:action])
57
+
58
+ submit_value = options[:submit_value] || options[:action].gsub(/[^\w]/, '').capitalize
59
+
60
+ id_field = record.new_record? ? "" : InstanceTag.new(record_name, "id", self).to_input_field_tag("hidden")
61
+
62
+ %(<form action="#{action}" method="post">#{id_field}) +
63
+ all_input_tags(record, record_name, options) +
64
+ %(<input type="submit" value="#{submit_value}" /></form>)
61
65
  end
62
66
 
63
67
  # Returns a string containing the error message attached to the +method+ on the +object+, if one exists.
@@ -76,14 +80,24 @@ module ActionView
76
80
  end
77
81
  end
78
82
 
79
- def error_messages_for(object_name)
80
- object = instance_eval("@#{object_name}")
83
+ # Returns a string with a div containing all the error messages for the object located as an instance variable by the name
84
+ # of <tt>object_name</tt>. This div can be tailored by the following options:
85
+ #
86
+ # * <tt>header_tag</tt> - Used for the header of the error div (default: h2)
87
+ # * <tt>id</tt> - The id of the error div (default: errorExplanation)
88
+ # * <tt>class</tt> - The class of the error div (default: errorExplanation)
89
+ def error_messages_for(object_name, options={})
90
+ object = instance_eval "@#{object_name}"
81
91
  unless object.errors.empty?
82
- "<div id=\"errorExplanation\">" +
83
- "<h2>#{object.errors.count} error#{"s" unless object.errors.count == 1} prohibited this #{object_name.gsub("_", " ")} from being saved</h2>" +
84
- "<p>There were problems with the following fields (marked in red below):</p>" +
85
- "<ul>#{object.errors.full_messages.collect { |msg| "<li>#{msg}</li>"}}</ul>" +
86
- "</div>"
92
+ content_tag("div",
93
+ content_tag(
94
+ options[:header_tag] || "h2",
95
+ "#{pluralize(object.errors.count, "error")} prohibited this #{object_name.gsub("_", " ")} from being saved"
96
+ ) +
97
+ content_tag("p", "There were problems with the following fields:") +
98
+ content_tag("ul", object.errors.full_messages.collect { |msg| content_tag("li", msg) }),
99
+ "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
100
+ )
87
101
  end
88
102
  end
89
103
 
@@ -143,8 +143,8 @@ module ActionView
143
143
  end
144
144
 
145
145
  month_options << ((date.kind_of?(Fixnum) ? date : date.month) == month_number ?
146
- "<option value='#{month_number}' selected=\"selected\">#{month_name}</option>\n" :
147
- "<option value='#{month_number}'>#{month_name}</option>\n"
146
+ %(<option value="#{month_number}" selected="selected">#{month_name}</option>\n) :
147
+ %(<option value="#{month_number}">#{month_name}</option>\n)
148
148
  )
149
149
  end
150
150
 
@@ -158,7 +158,8 @@ module ActionView
158
158
  # select_year(Date.today, :start_year => 1992, :end_year => 2007)
159
159
  def select_year(date, options = {})
160
160
  year_options = []
161
- unless date.kind_of?(Fixnum) then default_start_year, default_end_year = date.year - 5, date.year + 5 end
161
+ y = date.kind_of?(Fixnum) ? (y = (date == 0) ? Date.today.year : date) : date.year
162
+ default_start_year, default_end_year = y-5, y+5
162
163
 
163
164
  (options[:start_year] || default_start_year).upto(options[:end_year] || default_end_year) do |year|
164
165
  year_options << ((date.kind_of?(Fixnum) ? date : date.year) == year ?
@@ -172,9 +173,9 @@ module ActionView
172
173
 
173
174
  private
174
175
  def select_html(type, options, prefix = nil, include_blank = false, discard_type = false)
175
- select_html = "<select name='#{prefix || DEFAULT_PREFIX}"
176
+ select_html = %(<select name="#{prefix || DEFAULT_PREFIX})
176
177
  select_html << "[#{type}]" unless discard_type
177
- select_html << "'>\n"
178
+ select_html << %(">\n)
178
179
  select_html << "<option></option>\n" if include_blank
179
180
  select_html << options.to_s
180
181
  select_html << "</select>\n"
@@ -91,14 +91,30 @@ module ActionView
91
91
  #
92
92
  # Example (call, result). Imagine that @post.validated? returns 1:
93
93
  # check_box("post", "validated")
94
- # <input type="checkbox" id="post_validate" name="post[validated] value="1" checked="checked" /><input name="post[validated]" type="hidden" value="0" />
94
+ # <input type="checkbox" id="post_validate" name="post[validated] value="1" checked="checked" />
95
+ # <input name="post[validated]" type="hidden" value="0" />
95
96
  #
96
97
  # Example (call, result). Imagine that @puppy.gooddog returns no:
97
98
  # check_box("puppy", "gooddog", {}, "yes", "no")
98
- # <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog] value="yes" /><input name="puppy[gooddog]" type="hidden" value="no" />
99
+ # <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog] value="yes" />
100
+ # <input name="puppy[gooddog]" type="hidden" value="no" />
99
101
  def check_box(object, method, options = {}, checked_value = "1", unchecked_value = "0")
100
102
  InstanceTag.new(object, method, self).to_check_box_tag(options, checked_value, unchecked_value)
101
103
  end
104
+
105
+ # Returns a radio button tag for accessing a specified attribute (identified by +method+) on an object
106
+ # assigned to the template (identified by +object+). If the current value of +method+ is +tag_value+ the
107
+ # radio button will be checked. Additional options on the input tag can be passed as a
108
+ # hash with +options+.
109
+ # Example (call, result). Imagine that @post.category returns "rails":
110
+ # radio_button("post", "category", "rails")
111
+ # radio_button("post", "category", "java")
112
+ # <input type="radio" id="post_category" name="post[category] value="rails" checked="checked" />
113
+ # <input type="radio" id="post_category" name="post[category] value="java" />
114
+ #
115
+ def radio_button(object, method, tag_value, options = {})
116
+ InstanceTag.new(object, method, self).to_radio_button_tag(tag_value, options)
117
+ end
102
118
  end
103
119
 
104
120
  class InstanceTag #:nodoc:
@@ -117,7 +133,18 @@ module ActionView
117
133
  def to_input_field_tag(field_type, options = {})
118
134
  html_options = DEFAULT_FIELD_OPTIONS.merge(options)
119
135
  html_options.merge!({ "size" => options["maxlength"]}) if options["maxlength"] && !options["size"]
120
- html_options.merge!({ "type" => field_type, "value" => value.to_s })
136
+ html_options.delete("size") if field_type == "hidden"
137
+ html_options.merge!({ "type" => field_type})
138
+ html_options.merge!({ "value" => value.to_s }) unless options["value"]
139
+ add_default_name_and_id(html_options)
140
+ tag("input", html_options)
141
+ end
142
+
143
+ def to_radio_button_tag(tag_value, options={})
144
+ html_options = DEFAULT_FIELD_OPTIONS.merge(options)
145
+ html_options.merge!({"checked"=>"checked"}) if value == tag_value
146
+ html_options.merge!({"type"=>"radio", "value"=>tag_value.to_s})
147
+
121
148
  add_default_name_and_id(html_options)
122
149
  tag("input", html_options)
123
150
  end
@@ -179,4 +206,4 @@ module ActionView
179
206
  end
180
207
  end
181
208
  end
182
- end
209
+ end