aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/form_helper.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-04-30 17:14:28 -0500
committerJoshua Peek <josh@joshpeek.com>2008-04-30 17:14:28 -0500
commit96d9691e71319f4c166315a36b96c2c3c54ed493 (patch)
tree43bf8e70dc9cce11531a7ce9e017b7c11a1de95d /actionpack/lib/action_view/helpers/form_helper.rb
parentb4c33711c52dc78e6ff63469a5caa89f9a67c61a (diff)
downloadrails-96d9691e71319f4c166315a36b96c2c3c54ed493.tar.gz
rails-96d9691e71319f4c166315a36b96c2c3c54ed493.tar.bz2
rails-96d9691e71319f4c166315a36b96c2c3c54ed493.zip
FormHelper#label_tag accepts :for option [encoded] [#38 state:resolved]
Diffstat (limited to 'actionpack/lib/action_view/helpers/form_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb18
1 files changed, 10 insertions, 8 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 0e77a7e067..829f84dd64 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -1,6 +1,7 @@
require 'cgi'
require 'action_view/helpers/date_helper'
require 'action_view/helpers/tag_helper'
+require 'action_view/helpers/form_tag_helper'
module ActionView
module Helpers
@@ -51,7 +52,7 @@ module ActionView
#
# If the object name contains square brackets the id for the object will be inserted. For example:
#
- # <%= text_field "person[]", "name" %>
+ # <%= text_field "person[]", "name" %>
#
# ...will generate the following ERb.
#
@@ -91,7 +92,7 @@ module ActionView
#
# Even further, the form_for method allows you to more easily escape the instance variable convention. So while the stand-alone
# approach would require <tt>text_field :person, :name, :object => person</tt>
- # to work with local variables instead of instance ones, the form_for calls remain the same. You simply declare once with
+ # to work with local variables instead of instance ones, the form_for calls remain the same. You simply declare once with
# <tt>:person, person</tt> and all subsequent field calls save <tt>:person</tt> and <tt>:object => person</tt>.
#
# Also note that form_for doesn't create an exclusive scope. It's still possible to use both the stand-alone FormHelper methods
@@ -149,7 +150,7 @@ module ActionView
# ...
# <% end %>
#
- # And for namespaced routes, like admin_post_url:
+ # And for namespaced routes, like admin_post_url:
#
# <% form_for([:admin, @post]) do |f| %>
# ...
@@ -337,7 +338,7 @@ module ActionView
# hash with +options+. These options will be tagged onto the HTML as an HTML element attribute as in the example
# shown.
#
- # ==== Examples
+ # ==== Examples
# hidden_field(:signup, :pass_confirm)
# # => <input type="hidden" id="signup_pass_confirm" name="signup[pass_confirm]" value="#{@signup.pass_confirm}" />
#
@@ -404,7 +405,7 @@ module ActionView
# is set to 0 which is convenient for boolean values. Since HTTP standards say that unchecked checkboxes don't post anything,
# we add a hidden value with the same name as the checkbox as a work around.
#
- # ==== Examples
+ # ==== Examples
# # Let's say that @post.validated? is 1:
# check_box("post", "validated")
# # => <input type="checkbox" id="post_validated" name="post[validated]" value="1" />
@@ -445,7 +446,7 @@ module ActionView
end
class InstanceTag #:nodoc:
- include Helpers::TagHelper
+ include Helpers::TagHelper, Helpers::FormTagHelper
attr_reader :method_name, :object_name
@@ -467,11 +468,12 @@ module ActionView
end
def to_label_tag(text = nil, options = {})
+ options = options.stringify_keys
name_and_id = options.dup
add_default_name_and_id(name_and_id)
- options["for"] = name_and_id["id"]
+ options["for"] ||= name_and_id["id"]
content = (text.blank? ? nil : text.to_s) || method_name.humanize
- content_tag("label", content, options)
+ label_tag(name_and_id["id"], content, options)
end
def to_input_field_tag(field_type, options = {})