Skip to content
This repository
Browse code

Massive documentation update for all helpers (closes #8223, #8177, #8175

, #8108, #7977, #7972, #7971, #7969) [jeremymcanally]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7106 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit b00e6a984df51a2f891c2a4c819ac2ab08359eed 1 parent 8aefa3e
David Heinemeier Hansson authored June 23, 2007
108  actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -4,11 +4,15 @@
4 4
 
5 5
 module ActionView
6 6
   module Helpers #:nodoc:
7  
-    # Provides methods for linking an HTML page together with other assets such
8  
-    # as images, javascripts, stylesheets, and feeds. You can direct Rails to
9  
-    # link to assets from a dedicated assets server by setting ActionController::Base.asset_host
10  
-    # in your environment.rb. These methods do not verify the assets exist before
11  
-    # linking to them.
  7
+    # This module provides methods for generating HTML that links views to assets such
  8
+    # as images, javascripts, stylesheets, and feeds. These methods do not verify 
  9
+    # the assets exist before linking to them. 
  10
+    #
  11
+    # === Using asset hosts
  12
+    # By default, Rails links to these assets on the current host in the public
  13
+    # folder, but you can direct Rails to link to assets from a dedicated assets server by 
  14
+    # setting ActionController::Base.asset_host in your environment.rb.  For example,
  15
+    # let's say your asset host is assets.example.com. 
12 16
     #
13 17
     #   ActionController::Base.asset_host = "assets.example.com"
14 18
     #   image_tag("rails.png")
@@ -16,15 +20,22 @@ module Helpers #:nodoc:
16 20
     #   stylesheet_include_tag("application")
17 21
     #     => <link href="http://assets.example.com/stylesheets/application.css" media="screen" rel="Stylesheet" type="text/css" />
18 22
     #
19  
-    # Since browsers typically open at most two connections to a single host,
20  
-    # your assets often wait in single file for their turn to load.
  23
+    # This is useful since browsers typically open at most two connections to a single host,
  24
+    # which means your assets often wait in single file for their turn to load.  You can
  25
+    # alleviate this by using a %d wildcard in <tt>asset_host</tt> (for example, "assets%d.example.com") 
  26
+    # to automatically distribute asset requests among four hosts (e.g., assets0.example.com through assets3.example.com)
  27
+    # so browsers will open eight connections rather than two.  
  28
+    #
  29
+    #   image_tag("rails.png")
  30
+    #     => <img src="http://assets0.example.com/images/rails.png" alt="Rails" />
  31
+    #   stylesheet_include_tag("application")
  32
+    #     => <link href="http://assets3.example.com/stylesheets/application.css" media="screen" rel="Stylesheet" type="text/css" />
21 33
     #
22  
-    # Use a %d wildcard in asset_host (asset%d.myapp.com) to automatically
23  
-    # distribute asset requests among four hosts (asset0-asset3.myapp.com)
24  
-    # so browsers will open eight connections rather than two.  Use wildcard
25  
-    # DNS to CNAME the wildcard to your real asset host.
  34
+    # To do this, you can either setup four actual hosts, or you can use wildcard DNS to CNAME 
  35
+    # the wildcard to a single asset host.  You can read more about setting up your DNS CNAME records from
  36
+    # your ISP.
26 37
     #
27  
-    # Note: this is purely a browser performance optimization and is not meant
  38
+    # Note: This is purely a browser performance optimization and is not meant
28 39
     # for server load balancing. See http://www.die.net/musings/page_load_time/
29 40
     # for background.
30 41
     module AssetTagHelper
@@ -37,19 +48,24 @@ module AssetTagHelper
37 48
       # <tt>:atom</tt>. Control the link options in url_for format using the
38 49
       # +url_options+. You can modify the LINK tag itself in +tag_options+.
39 50
       #
40  
-      # Tag Options:
  51
+      # ==== Options:
41 52
       # * <tt>:rel</tt>  - Specify the relation of this link, defaults to "alternate"
42 53
       # * <tt>:type</tt>  - Override the auto-generated mime type
43 54
       # * <tt>:title</tt>  - Specify the title of the link, defaults to the +type+
44 55
       #
  56
+      # ==== Examples
45 57
       #  auto_discovery_link_tag # =>
46  
-      #     <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.curenthost.com/controller/action" />
  58
+      #     <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.currenthost.com/controller/action" />
47 59
       #  auto_discovery_link_tag(:atom) # =>
48  
-      #     <link rel="alternate" type="application/atom+xml" title="ATOM" href="http://www.curenthost.com/controller/action" />
  60
+      #     <link rel="alternate" type="application/atom+xml" title="ATOM" href="http://www.currenthost.com/controller/action" />
49 61
       #  auto_discovery_link_tag(:rss, {:action => "feed"}) # =>
50  
-      #     <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.curenthost.com/controller/feed" />
  62
+      #     <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.currenthost.com/controller/feed" />
51 63
       #  auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "My RSS"}) # =>
52  
-      #     <link rel="alternate" type="application/rss+xml" title="My RSS" href="http://www.curenthost.com/controller/feed" />
  64
+      #     <link rel="alternate" type="application/rss+xml" title="My RSS" href="http://www.currenthost.com/controller/feed" />
  65
+      #  auto_discovery_link_tag(:rss, {:controller => "news", :action => "feed"}) # =>
  66
+      #     <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.currenthost.com/news/feed" />
  67
+      #  auto_discovery_link_tag(:rss, "http://www.example.com/feed.rss", {:title => "Example RSS"}) # =>
  68
+      #     <link rel="alternate" type="application/rss+xml" title="Example RSS" href="http://www.example.com/feed" />
53 69
       def auto_discovery_link_tag(type = :rss, url_options = {}, tag_options = {})
54 70
         tag(
55 71
           "link",
@@ -65,9 +81,12 @@ def auto_discovery_link_tag(type = :rss, url_options = {}, tag_options = {})
65 81
       # Full paths from the document root will be passed through.
66 82
       # Used internally by javascript_include_tag to build the script path.
67 83
       #
  84
+      # ==== Examples
68 85
       #   javascript_path "xmlhr" # => /javascripts/xmlhr.js
69 86
       #   javascript_path "dir/xmlhr.js" # => /javascripts/dir/xmlhr.js
70 87
       #   javascript_path "/dir/xmlhr" # => /dir/xmlhr.js
  88
+      #   javascript_path "http://www.railsapplication.com/js/xmlhr" # => http://www.railsapplication.com/js/xmlhr.js
  89
+      #   javascript_path "http://www.railsapplication.com/js/xmlhr.js" # => http://www.railsapplication.com/js/xmlhr.js
71 90
       def javascript_path(source)
72 91
         compute_public_path(source, 'javascripts', 'js')
73 92
       end
@@ -85,22 +104,35 @@ def javascript_path(source)
85 104
       # javascripts directory, it will be included as well. You can modify the
86 105
       # html attributes of the script tag by passing a hash as the last argument.
87 106
       #
  107
+      # ==== Examples
88 108
       #   javascript_include_tag "xmlhr" # =>
89 109
       #     <script type="text/javascript" src="/javascripts/xmlhr.js"></script>
90 110
       #
  111
+      #   javascript_include_tag "xmlhr.js" # =>
  112
+      #     <script type="text/javascript" src="/javascripts/xmlhr.js"></script>
  113
+      #
91 114
       #   javascript_include_tag "common.javascript", "/elsewhere/cools" # =>
92 115
       #     <script type="text/javascript" src="/javascripts/common.javascript"></script>
93 116
       #     <script type="text/javascript" src="/elsewhere/cools.js"></script>
94 117
       #
  118
+      #   javascript_include_tag "http://www.railsapplication.com/xmlhr" # =>
  119
+      #     <script type="text/javascript" src="http://www.railsapplication.com/xmlhr.js"></script>
  120
+      #
  121
+      #   javascript_include_tag "http://www.railsapplication.com/xmlhr.js" # =>
  122
+      #     <script type="text/javascript" src="http://www.railsapplication.com/xmlhr.js"></script>
  123
+      #
95 124
       #   javascript_include_tag :defaults # =>
96 125
       #     <script type="text/javascript" src="/javascripts/prototype.js"></script>
97 126
       #     <script type="text/javascript" src="/javascripts/effects.js"></script>
98 127
       #     ...
99  
-      #     <script type="text/javascript" src="/javascripts/application.js"></script> *see below
  128
+      #     <script type="text/javascript" src="/javascripts/application.js"></script> <!-- * see below -->
100 129
       #
101 130
       # * = The application.js file is only referenced if it exists
102 131
       #
103  
-      # You can also include all javascripts in the javascripts directory using :all as the source:
  132
+      # Though it's not really recommended practice, if you need to extend the default JavaScript set for any reason 
  133
+      # (e.g., you're going to be using a certain .js file in every action), then take a look at the register_javascript_include_default method.
  134
+      #
  135
+      # You can also include all javascripts in the javascripts directory using <tt>:all</tt> as the source:
104 136
       #
105 137
       #   javascript_include_tag :all # =>
106 138
       #     <script type="text/javascript" src="/javascripts/prototype.js"></script>
@@ -110,16 +142,17 @@ def javascript_path(source)
110 142
       #     <script type="text/javascript" src="/javascripts/shop.js"></script>
111 143
       #     <script type="text/javascript" src="/javascripts/checkout.js"></script>
112 144
       #
113  
-      # Note that the default javascript files will be included first. So Prototype and Scriptaculous are available for
114  
-      # all subsequently included files. They
  145
+      # Note that the default javascript files will be included first. So Prototype and Scriptaculous are available to
  146
+      # all subsequently included files.
115 147
       #
116 148
       # == Caching multiple javascripts into one
117 149
       #
118  
-      # You can also cache multiple javascripts into one file, which requires less HTTP connections and can better be
  150
+      # You can also cache multiple javascripts into one file, which requires less HTTP connections to download and can better be
119 151
       # compressed by gzip (leading to faster transfers). Caching will only happen if ActionController::Base.perform_caching
120  
-      # is set to true (which is the case by default for the Rails production environment, but not for the development
121  
-      # environment). Examples:
  152
+      # is set to <tt>true</tt> (which is the case by default for the Rails production environment, but not for the development
  153
+      # environment). 
122 154
       #
  155
+      # ==== Examples
123 156
       #   javascript_include_tag :all, :cache => true # when ActionController::Base.perform_caching is false =>
124 157
       #     <script type="text/javascript" src="/javascripts/prototype.js"></script>
125 158
       #     <script type="text/javascript" src="/javascripts/effects.js"></script>
@@ -168,7 +201,7 @@ def javascript_include_tag(*sources)
168 201
 
169 202
       # Register one or more additional JavaScript files to be included when
170 203
       # <tt>javascript_include_tag :defaults</tt> is called. This method is
171  
-      # only intended to be called from plugin initialization to register additional
  204
+      # typically intended to be called from plugin initialization to register additional
172 205
       # .js files that the plugin installed in <tt>public/javascripts</tt>.
173 206
       def self.register_javascript_include_default(*sources)
174 207
         @@javascript_default_sources.concat(sources)
@@ -183,9 +216,12 @@ def self.reset_javascript_include_default #:nodoc:
183 216
       # Full paths from the document root will be passed through.
184 217
       # Used internally by stylesheet_link_tag to build the stylesheet path.
185 218
       #
  219
+      # ==== Examples
186 220
       #   stylesheet_path "style" # => /stylesheets/style.css
187 221
       #   stylesheet_path "dir/style.css" # => /stylesheets/dir/style.css
188 222
       #   stylesheet_path "/dir/style.css" # => /dir/style.css
  223
+      #   stylesheet_path "http://www.railsapplication.com/css/style" # => http://www.railsapplication.com/css/style.css
  224
+      #   stylesheet_path "http://www.railsapplication.com/css/style.js" # => http://www.railsapplication.com/css/style.css
189 225
       def stylesheet_path(source)
190 226
         compute_public_path(source, 'stylesheets', 'css')
191 227
       end
@@ -194,12 +230,22 @@ def stylesheet_path(source)
194 230
       # you don't specify an extension, .css will be appended automatically.
195 231
       # You can modify the link attributes by passing a hash as the last argument.
196 232
       #
  233
+      # ==== Examples
197 234
       #   stylesheet_link_tag "style" # =>
198 235
       #     <link href="/stylesheets/style.css" media="screen" rel="Stylesheet" type="text/css" />
199 236
       #
  237
+      #   stylesheet_link_tag "style.css" # =>
  238
+      #     <link href="/stylesheets/style.css" media="screen" rel="Stylesheet" type="text/css" />
  239
+      #
  240
+      #   stylesheet_link_tag "http://www.railsapplication.com/style.css" # =>
  241
+      #     <link href="http://www.railsapplication.com/style.css" media="screen" rel="Stylesheet" type="text/css" />
  242
+      #
200 243
       #   stylesheet_link_tag "style", :media => "all" # =>
201 244
       #     <link href="/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css" />
202 245
       #
  246
+      #   stylesheet_link_tag "style", :media => "print" # =>
  247
+      #     <link href="/stylesheets/style.css" media="print" rel="Stylesheet" type="text/css" />
  248
+      #
203 249
       #   stylesheet_link_tag "random.styles", "/css/stylish" # =>
204 250
       #     <link href="/stylesheets/random.styles" media="screen" rel="Stylesheet" type="text/css" />
205 251
       #     <link href="/css/stylish.css" media="screen" rel="Stylesheet" type="text/css" />
@@ -218,6 +264,7 @@ def stylesheet_path(source)
218 264
       # is set to true (which is the case by default for the Rails production environment, but not for the development
219 265
       # environment). Examples:
220 266
       #
  267
+      # ==== Examples
221 268
       #   stylesheet_link_tag :all, :cache => true # when ActionController::Base.perform_caching is false =>
222 269
       #     <link href="/stylesheets/style1.css"  media="screen" rel="Stylesheet" type="text/css" />
223 270
       #     <link href="/stylesheets/styleB.css"  media="screen" rel="Stylesheet" type="text/css" />
@@ -271,9 +318,11 @@ def stylesheet_link_tag(*sources)
271 318
       # Used internally by image_tag to build the image path. Passing
272 319
       # a filename without an extension is deprecated.
273 320
       #
  321
+      # ==== Examples
274 322
       #   image_path("edit.png")  # => /images/edit.png
275 323
       #   image_path("icons/edit.png")  # => /images/icons/edit.png
276 324
       #   image_path("/icons/edit.png")  # => /icons/edit.png
  325
+      #   image_path("http://www.railsapplication.com/img/edit.png") # => http://www.railsapplication.com/img/edit.png
277 326
       def image_path(source)
278 327
         unless (source.split("/").last || source).include?(".") || source.blank?
279 328
           ActiveSupport::Deprecation.warn(
@@ -289,7 +338,9 @@ def image_path(source)
289 338
       # Returns an html image tag for the +source+. The +source+ can be a full
290 339
       # path or a file that exists in your public images directory. Note that
291 340
       # specifying a filename without the extension is now deprecated in Rails.
292  
-      # You can add html attributes using the +options+. The +options+ supports
  341
+      #
  342
+      # ==== Options
  343
+      # You can add HTML attributes using the +options+. The +options+ supports
293 344
       # two additional keys for convienence and conformance:
294 345
       #
295 346
       # * <tt>:alt</tt>  - If no alt text is given, the file name part of the
@@ -298,12 +349,17 @@ def image_path(source)
298 349
       #   width="30" and height="45". <tt>:size</tt> will be ignored if the
299 350
       #   value is not in the correct format.
300 351
       #
  352
+      # ==== Examples
301 353
       #  image_tag("icon.png")  # =>
302 354
       #    <img src="/images/icon.png" alt="Icon" />
303 355
       #  image_tag("icon.png", :size => "16x10", :alt => "Edit Entry")  # =>
304 356
       #    <img src="/images/icon.png" width="16" height="10" alt="Edit Entry" />
305 357
       #  image_tag("/icons/icon.gif", :size => "16x16")  # =>
306 358
       #    <img src="/icons/icon.gif" width="16" height="16" alt="Icon" />
  359
+      #  image_tag("/icons/icon.gif", :height => '32', :width => '32') # =>
  360
+      #    <img alt="Icon" height="32" src="/icons/icon.gif" width="32" />
  361
+      #  image_tag("/icons/icon.gif", :class => "menu_icon") # =>
  362
+      #    <img alt="Icon" class="menu_icon" src="/icons/icon.gif" />
307 363
       def image_tag(source, options = {})
308 364
         options.symbolize_keys!
309 365
 
17  actionpack/lib/action_view/helpers/benchmark_helper.rb
@@ -2,17 +2,24 @@
2 2
 
3 3
 module ActionView
4 4
   module Helpers
  5
+    # This helper offers a method to measure the execution time of a block 
  6
+    # in a template.
5 7
     module BenchmarkHelper
6  
-      # Measures the execution time of a block in a template and reports the result to the log. Example:
  8
+      # Allows you to measure the execution time of a block 
  9
+      # in a template and records the result to the log. Wrap this block around
  10
+      # expensive operations or possible bottlenecks to get a time reading
  11
+      # for the operation.  For example, let's say you thought your file 
  12
+      # processing method was taking too long; you could wrap it in a benchmark block.
7 13
       #
8  
-      #  <% benchmark "Notes section" do %>
9  
-      #    <%= expensive_notes_operation %>
  14
+      #  <% benchmark "Process data files" do %>
  15
+      #    <%= expensive_files_operation %>
10 16
       #  <% end %>
11 17
       #
12  
-      # Will add something like "Notes section (0.34523)" to the log.
  18
+      # That would add something like "Process data files (0.34523)" to the log,
  19
+      # which you can then use to compare timings when optimizing your code.
13 20
       #
14 21
       # You may give an optional logger level as the second argument
15  
-      # (:debug, :info, :warn, :error).  The default is :info.
  22
+      # (:debug, :info, :warn, :error); the default value is :info.
16 23
       def benchmark(message = "Benchmarking", level = :info)
17 24
         if @logger
18 25
           real = Benchmark.realtime { yield }
29  actionpack/lib/action_view/helpers/cache_helper.rb
... ...
@@ -1,7 +1,36 @@
1 1
 module ActionView
2 2
   module Helpers
  3
+    # This helper to exposes a method for caching of view fragments.
3 4
     # See ActionController::Caching::Fragments for usage instructions.
4 5
     module CacheHelper
  6
+      # A method for caching fragments of a view rather than an entire
  7
+      # action or page.  This technique is useful caching pieces like
  8
+      # menus, lists of news topics, static HTML fragments, and so on.
  9
+      # This method takes a block that contains the content you wish
  10
+      # to cache.  See ActionController::Caching::Fragments for more
  11
+      # information.
  12
+      #
  13
+      # ==== Examples
  14
+      # If you wanted to cache a navigation menu, you could do the
  15
+      # following.
  16
+      #
  17
+      #   <% cache do %>
  18
+      #     <%= render :partial => "menu" %>
  19
+      #   <% end %>
  20
+      #
  21
+      # You can also cache static content...
  22
+      #
  23
+      #   <% cache do %>
  24
+      #      <p>Hello users!  Welcome to our website!</p>
  25
+      #   <% end %>
  26
+      #
  27
+      # ...and static content mixed with RHTML content.
  28
+      #
  29
+      #    <% cache do %>
  30
+      #      Topics:
  31
+      #      <%= render :partial => "topics", :collection => @topic_list %>
  32
+      #      <i>Topics listed alphabetically</i>
  33
+      #    <% end %>
5 34
       def cache(name = {}, &block)
6 35
         @controller.cache_erb_fragment(block, name)
7 36
       end
118  actionpack/lib/action_view/helpers/capture_helper.rb
... ...
@@ -1,58 +1,36 @@
1 1
 module ActionView
2 2
   module Helpers
3  
-    # Capture lets you extract parts of code which
4  
-    # can be used in other points of the template or even layout file.
5  
-    #
6  
-    # == Capturing a block into an instance variable
7  
-    #
8  
-    #   <% @script = capture do %>
9  
-    #     [some html...]
10  
-    #   <% end %>
11  
-    #
12  
-    # == Add javascript to header using content_for
13  
-    #
14  
-    # content_for("name") is a wrapper for capture which will 
15  
-    # make the fragment available by name to a yielding layout or template.
16  
-    #
17  
-    # layout.erb:
18  
-    #
19  
-    #   <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
20  
-    #   <head>
21  
-    #	    <title>layout with js</title>
22  
-    #	    <script type="text/javascript">
23  
-    #	      <%= yield :script %>
24  
-    #     </script>
25  
-    #   </head>
26  
-    #   <body>
27  
-    #     <%= yield %>
28  
-    #   </body>
29  
-    #   </html>
30  
-    #
31  
-    # view.erb
32  
-    #   
33  
-    #   This page shows an alert box!
34  
-    #
35  
-    #   <% content_for("script") do %>
36  
-    #     alert('hello world')
37  
-    #   <% end %>
38  
-    #
39  
-    #   Normal view text
  3
+    # CaptureHelper exposes methods to let you extract generated markup which
  4
+    # can be used in other parts of a template or layout file.
  5
+    # It provides a method to capture blocks into variables through capture and 
  6
+    # a way to capture a block of code for use in a layout through content_for.
40 7
     module CaptureHelper
41  
-      # Capture allows you to extract a part of the template into an 
42  
-      # instance variable. You can use this instance variable anywhere
43  
-      # in your templates and even in your layout. 
  8
+      # The capture method allows you to extract a part of the template into a 
  9
+      # variable. You can then use this value anywhere in your templates or layout. 
44 10
       # 
45  
-      # Example of capture being used in a .erb page:
  11
+      # ==== Examples
  12
+      # The capture method can be used in RHTML (ERb) templates...
46 13
       # 
47 14
       #   <% @greeting = capture do %>
48  
-      #     Welcome To my shiny new web page!
  15
+      #     Welcome to my shiny new web page!  The date and time is
  16
+      #     <%= Time.now %>
49 17
       #   <% end %>
50 18
       #
51  
-      # Example of capture being used in a .builder page:
  19
+      # ...and Builder (RXML) templates.
52 20
       # 
53  
-      #   @greeting = capture do
54  
-      #     'Welcome To my shiny new web page!'
  21
+      #   @timestamp = capture do
  22
+      #     "The current timestamp is #{Time.now}."
55 23
       #   end
  24
+      #
  25
+      # You can then use the content as a variable anywhere else.  For
  26
+      # example:
  27
+      #
  28
+      #   <html>
  29
+      #   <head><title><%= @greeting %></title></head>
  30
+      #   <body>
  31
+      #   <b><%= @greeting %></b>
  32
+      #   </body></html>
  33
+      #
56 34
       def capture(*args, &block)
57 35
         # execute the block
58 36
         begin
@@ -68,19 +46,53 @@ def capture(*args, &block)
68 46
         end
69 47
       end
70 48
       
71  
-      # Calling content_for stores the block of markup for later use.
72  
-      # Subsequently, you can make calls to it by name with <tt>yield</tt>
73  
-      # in another template or in the layout. 
  49
+      # Calling content_for stores the block of markup in an identifier for later use.
  50
+      # You can make subsequent calls to the stored content in another template or in the layout
  51
+      # by calling it by name with <tt>yield</tt>.
74 52
       # 
75  
-      # Example:
  53
+      # ==== Examples
76 54
       # 
77  
-      #   <% content_for("header") do %>
78  
-      #     alert('hello world')
  55
+      #   <% content_for("authorized") do %>
  56
+      #     alert('You are not authorized for that!')
  57
+      #   <% end %>
  58
+      #
  59
+      # You can then use <tt>yield :authorized</tt> anywhere in your templates.
  60
+      #
  61
+      #   <%= yield :authorized if current_user == nil %>
  62
+      #
  63
+      # You can also use these variables in a layout.  For example:
  64
+      #
  65
+      #   <!-- This is the layout -->
  66
+      #   <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  67
+      #   <head>
  68
+      #	    <title>My Website</title>
  69
+      #	    <%= yield :script %>
  70
+      #   </head>
  71
+      #   <body>
  72
+      #     <%= yield %>
  73
+      #   </body>
  74
+      #   </html>
  75
+      #
  76
+      # And now we'll create a view that has a content_for call that
  77
+      # creates the <tt>script</tt> identifier.
  78
+      #
  79
+      #   <!-- This is our view -->
  80
+      #   Please login!
  81
+      #
  82
+      #   <% content_for("script") do %>
  83
+      #     <script type="text/javascript">alert('You are not authorized for this action!')</script>
79 84
       #   <% end %>
80 85
       #
81  
-      # You can use yield :header anywhere in your templates.
  86
+      # Then in another view you may want to do something like this:
  87
+      #
  88
+      #   <%= link_to_remote 'Logout', :action => 'logout' %>
  89
+      #
  90
+      #   <% content_for("script") do %>
  91
+      #     <%= javascript_include_tag :defaults %>
  92
+      #   <% end %>
82 93
       #
83  
-      #   <%= yield :header %>
  94
+      # That will include Prototype and Scriptaculous into the page; this technique
  95
+      # is useful if you'll only be using these scripts on a few views.
84 96
       #
85 97
       # NOTE: Beware that content_for is ignored in caches. So you shouldn't use it
86 98
       # for elements that are going to be fragment cached.
268  actionpack/lib/action_view/helpers/date_helper.rb
@@ -37,12 +37,24 @@ module DateHelper
37 37
       # 40-59 secs      # => less than a minute
38 38
       # 60-89 secs      # => 1 minute
39 39
       #
40  
-      # Examples:
41  
-      #
  40
+      # ==== Examples
42 41
       #   from_time = Time.now
43  
-      #   distance_of_time_in_words(from_time, from_time + 50.minutes) # => about 1 hour
44  
-      #   distance_of_time_in_words(from_time, from_time + 15.seconds) # => less than a minute
45  
-      #   distance_of_time_in_words(from_time, from_time + 15.seconds, true) # => less than 20 seconds
  42
+      #   distance_of_time_in_words(from_time, from_time + 50.minutes)        # => about 1 hour
  43
+      #   distance_of_time_in_words(from_time, 50.minutes.from_now)           # => about 1 hour
  44
+      #   distance_of_time_in_words(from_time, from_time + 15.seconds)        # => less than a minute
  45
+      #   distance_of_time_in_words(from_time, from_time + 15.seconds, true)  # => less than 20 seconds
  46
+      #   distance_of_time_in_words(from_time, 3.years.from_now)              # => over 3 years
  47
+      #   distance_of_time_in_words(from_time, from_time + 60.hours)          # => about 3 days
  48
+      #   distance_of_time_in_words(from_time, from_time + 45.seconds, true)  # => less than a minute
  49
+      #   distance_of_time_in_words(from_time, from_time - 45.seconds, true)  # => less than a minute
  50
+      #   distance_of_time_in_words(from_time, 76.seconds.from_now)           # => 1 minute
  51
+      #   distance_of_time_in_words(from_time, from_time + 1.year + 3.days)   # => about 1 years
  52
+      #   distance_of_time_in_words(from_time, from_time + 4.years + 15.days + 30.minutes + 5.seconds) # => over 4 years
  53
+      #
  54
+      #   to_time = Time.now + 6.years + 19.days
  55
+      #   distance_of_time_in_words(from_time, to_time, true)     # => over 6 years
  56
+      #   distance_of_time_in_words(to_time, from_time, true)     # => over 6 years
  57
+      #   distance_of_time_in_words(Time.now, Time.now)           # => less than a minute
46 58
       #
47 59
       # Note: Rails calculates one year as 365.25 days.
48 60
       def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false)
@@ -76,6 +88,13 @@ def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false)
76 88
       end
77 89
 
78 90
       # Like distance_of_time_in_words, but where <tt>to_time</tt> is fixed to <tt>Time.now</tt>.
  91
+      #
  92
+      # ==== Examples
  93
+      #   time_ago_in_words(3.minutes.from_now)       # => 3 minutes
  94
+      #   time_ago_in_words(Time.now - 15.hours)      # => 15 hours
  95
+      #   time_ago_in_words(Time.now)                 # => less than a minute
  96
+      #
  97
+      #   from_time = Time.now - 3.days - 14.minutes - 25.seconds     # => 3 days
79 98
       def time_ago_in_words(from_time, include_seconds = false)
80 99
         distance_of_time_in_words(from_time, Time.now, include_seconds)
81 100
       end
@@ -96,16 +115,34 @@ def time_ago_in_words(from_time, include_seconds = false)
96 115
       #
97 116
       # NOTE: Discarded selects will default to 1. So if no month select is available, January will be assumed.
98 117
       #
99  
-      # Examples:
100  
-      #
  118
+      # ==== Examples
  119
+      #   # Generates a date select that when POSTed is stored in the post variable, in the written_on attribute
101 120
       #   date_select("post", "written_on")
  121
+      #
  122
+      #   # Generates a date select that when POSTed is stored in the post variable, in the written_on attribute,
  123
+      #   # with the year in the year drop down box starting at 1995.
102 124
       #   date_select("post", "written_on", :start_year => 1995)
  125
+      #
  126
+      #   # Generates a date select that when POSTed is stored in the post variable, in the written_on attribute,
  127
+      #   # with the year in the year drop down box starting at 1995, numbers used for months instead of words,
  128
+      #   # and without a day select box. 
103 129
       #   date_select("post", "written_on", :start_year => 1995, :use_month_numbers => true,
104 130
       #                                     :discard_day => true, :include_blank => true)
  131
+      #
  132
+      #   # Generates a date select that when POSTed is stored in the post variable, in the written_on attribute
  133
+      #   # with the fields ordered as day, month, year rather than month, day, year.
105 134
       #   date_select("post", "written_on", :order => [:day, :month, :year])
106  
-      #   date_select("user", "birthday",   :order => [:month, :day])
107 135
       #
  136
+      #   # Generates a date select that when POSTed is stored in the user variable, in the birthday attribute
  137
+      #   # lacking a year field.
  138
+      #   date_select("user", "birthday", :order => [:month, :day])
  139
+      #
  140
+      #   # Generates a date select that when POSTed is stored in the user variable, in the birthday attribute
  141
+      #   # which is initially set to the date 3 days from the current date
108 142
       #   date_select("post", "written_on", :default => 3.days.from_now)
  143
+      #
  144
+      #   # Generates a date select that when POSTed is stored in the credit_card variable, in the bill_due attribute
  145
+      #   # that will have a default day of 20.
109 146
       #   date_select("credit_card", "bill_due", :default => { :day => 20 })
110 147
       #
111 148
       # The selects are prepared for multi-parameter assignment to an Active Record object.
@@ -119,11 +156,25 @@ def date_select(object_name, method, options = {})
119 156
       # Returns a set of select tags (one for hour, minute and optionally second) pre-selected for accessing a specified
120 157
       # time-based attribute (identified by +method+) on an object assigned to the template (identified by +object+).
121 158
       # You can include the seconds with <tt>:include_seconds</tt>.
122  
-      # Examples:
123  
-      #
  159
+      # 
  160
+      # ==== Examples
  161
+      #   # Creates a time select tag that, when POSTed, will be stored in the post variable in the sunrise attribute
124 162
       #   time_select("post", "sunrise")
  163
+      #
  164
+      #   # Creates a time select tag that, when POSTed, will be stored in the order variable in the submitted attribute
  165
+      #   time_select("order", "submitted")
  166
+      #
  167
+      #   # Creates a time select tag that, when POSTed, will be stored in the mail variable in the sent_at attribute
  168
+      #   time_select("mail", "sent_at")
  169
+      #
  170
+      #   # Creates a time select tag with a seconds field that, when POSTed, will be stored in the post variables in 
  171
+      #   # the sunrise attribute. 
125 172
       #   time_select("post", "start_time", :include_seconds => true)
126 173
       #
  174
+      #   # Creates a time select tag with a seconds field that, when POSTed, will be stored in the entry variables in 
  175
+      #   # the submission_time attribute. 
  176
+      #   time_select("entry", "submission_time", :include_seconds => true)
  177
+      #
127 178
       # The selects are prepared for multi-parameter assignment to an Active Record object.
128 179
       #
129 180
       # Note: If the day is not included as an option but the month is, the day will be set to the 1st to ensure that all month
@@ -135,9 +186,22 @@ def time_select(object_name, method, options = {})
135 186
       # Returns a set of select tags (one for year, month, day, hour, and minute) pre-selected for accessing a specified datetime-based
136 187
       # attribute (identified by +method+) on an object assigned to the template (identified by +object+). Examples:
137 188
       #
  189
+      # ==== Examples
  190
+      #   # Generates a datetime select that, when POSTed, will be stored in the post variable in the written_on attribute
138 191
       #   datetime_select("post", "written_on")
  192
+      #
  193
+      #   # Generates a datetime select with a year select that starts at 1995 that, when POSTed, will be stored in the 
  194
+      #   # post variable in the written_on attribute.
139 195
       #   datetime_select("post", "written_on", :start_year => 1995)
140 196
       #
  197
+      #   # Generates a datetime select with a default value of 3 days from the current time that, when POSTed, will be stored in the 
  198
+      #   # trip variable in the departing attribute.
  199
+      #   datetime_select("trip", "departing", :default => 3.days.from_now)
  200
+      #
  201
+      #   # Generates a datetime select that discards the type that, when POSTed, will be stored in the post variable as the written_on
  202
+      #   # attribute.
  203
+      #   datetime_select("post", "written_on", :discard_type => true)
  204
+      #
141 205
       # The selects are prepared for multi-parameter assignment to an Active Record object.
142 206
       def datetime_select(object_name, method, options = {})
143 207
         InstanceTag.new(object_name, method, self, nil, options.delete(:object)).to_datetime_select_tag(options)
@@ -148,7 +212,33 @@ def datetime_select(object_name, method, options = {})
148 212
       # symbols <tt>:year</tt>, <tt>:month</tt> and <tt>:day</tt> in the desired order. If you do not supply a Symbol, it
149 213
       # will be appened onto the <tt>:order</tt> passed in. You can also add <tt>:date_separator</tt> and <tt>:time_separator</tt>
150 214
       # keys to the +options+ to control visual display of the elements.
151  
-       def select_datetime(datetime = Time.now, options = {})
  215
+      #
  216
+      # ==== Examples
  217
+      #   my_date_time = Time.now + 4.days
  218
+      #
  219
+      #   # Generates a datetime select that defaults to the datetime in my_date_time (four days after today)
  220
+      #   select_datetime(my_date_time)
  221
+      #
  222
+      #   # Generates a datetime select that defaults to today (no specified datetime)
  223
+      #   select_datetime()
  224
+      #
  225
+      #   # Generates a datetime select that defaults to the datetime in my_date_time (four days after today)
  226
+      #   # with the fields ordered year, month, day rather then month, day, year.
  227
+      #   select_datetime(my_date_time, :order => [:year, :month, :day])
  228
+      #
  229
+      #   # Generates a datetime select that defaults to the datetime in my_date_time (four days after today)
  230
+      #   # with a '/' between each date field.
  231
+      #   select_datetime(my_date_time, :date_separator => '/')
  232
+      #
  233
+      #   # Generates a datetime select that discards the type of the field and defaults to the datetime in 
  234
+      #   # my_date_time (four days after today)
  235
+      #   select_datetime(my_date_time, :discard_type => true)
  236
+      #
  237
+      #   # Generates a datetime select that defaults to the datetime in my_date_time (four days after today)
  238
+      #   # prefixed with 'payday' rather than 'date'
  239
+      #   select_datetime(my_date_time, :prefix => 'payday')
  240
+      #
  241
+      def select_datetime(datetime = Time.now, options = {})
152 242
         separator = options[:datetime_separator] || ''
153 243
         select_date(datetime, options) + separator + select_time(datetime, options)
154 244
        end
@@ -157,6 +247,28 @@ def select_datetime(datetime = Time.now, options = {})
157 247
       # It's possible to explicitly set the order of the tags using the <tt>:order</tt> option with an array of
158 248
       # symbols <tt>:year</tt>, <tt>:month</tt> and <tt>:day</tt> in the desired order. If you do not supply a Symbol, it
159 249
       # will be appened onto the <tt>:order</tt> passed in.
  250
+      #
  251
+      # ==== Examples
  252
+      #   my_date = Time.today + 6.days
  253
+      #
  254
+      #   # Generates a date select that defaults to the date in my_date (six days after today)
  255
+      #   select_date(my_date)
  256
+      #
  257
+      #   # Generates a date select that defaults to today (no specified date)
  258
+      #   select_date()
  259
+      #
  260
+      #   # Generates a date select that defaults to the date in my_date (six days after today)
  261
+      #   # with the fields ordered year, month, day rather then month, day, year.
  262
+      #   select_date(my_date, :order => [:year, :month, :day])
  263
+      #
  264
+      #   # Generates a date select that discards the type of the field and defaults to the date in 
  265
+      #   # my_date (six days after today)
  266
+      #   select_datetime(my_date_time, :discard_type => true)
  267
+      #
  268
+      #   # Generates a date select that defaults to the datetime in my_date (six days after today)
  269
+      #   # prefixed with 'payday' rather than 'date'
  270
+      #   select_datetime(my_date_time, :prefix => 'payday')
  271
+      #
160 272
       def select_date(date = Date.today, options = {})
161 273
         options[:order] ||= []
162 274
         [:year, :month, :day].each { |o| options[:order].push(o) unless options[:order].include?(o) }
@@ -169,7 +281,30 @@ def select_date(date = Date.today, options = {})
169 281
       end
170 282
 
171 283
       # Returns a set of html select-tags (one for hour and minute)
172  
-      # You can set <tt>:add_separator</tt> key to format the output.
  284
+      # You can set <tt>:time_separator</tt> key to format the output, and 
  285
+      # the <tt>:include_seconds</tt> option to include an input for seconds.
  286
+      #
  287
+      # ==== Examples
  288
+      #   my_time = Time.now + 5.days + 7.hours + 3.minutes + 14.seconds
  289
+      #
  290
+      #   # Generates a time select that defaults to the time in my_time
  291
+      #   select_time(my_time)
  292
+      #
  293
+      #   # Generates a time select that defaults to the current time (no specified time)
  294
+      #   select_time()
  295
+      #
  296
+      #   # Generates a time select that defaults to the time in my_time,
  297
+      #   # which has fields separated by ':' 
  298
+      #   select_time(my_time, :time_separator => ':')
  299
+      #
  300
+      #   # Generates a time select that defaults to the time in my_time,
  301
+      #   # that also includes an input for seconds
  302
+      #   select_time(my_time, :include_seconds => true)
  303
+      #
  304
+      #   # Generates a time select that defaults to the time in my_time, that has fields
  305
+      #   # separated by ':' and includes an input for seconds
  306
+      #   select_time(my_time, :time_separator => ':', :include_seconds => true)
  307
+      #
173 308
       def select_time(datetime = Time.now, options = {})
174 309
         separator = options[:time_separator] || ''
175 310
         select_hour(datetime, options) + separator + select_minute(datetime, options) + (options[:include_seconds] ? separator + select_second(datetime, options) : '')
@@ -178,6 +313,20 @@ def select_time(datetime = Time.now, options = {})
178 313
       # Returns a select tag with options for each of the seconds 0 through 59 with the current second selected.
179 314
       # The <tt>second</tt> can also be substituted for a second number.
180 315
       # Override the field name using the <tt>:field_name</tt> option, 'second' by default.
  316
+      #
  317
+      # ==== Examples
  318
+      #   my_time = Time.now + 16.minutes
  319
+      #
  320
+      #   # Generates a select field for seconds that defaults to the seconds for the time in my_time
  321
+      #   select_second(my_time)
  322
+      #
  323
+      #   # Generates a select field for seconds that defaults to the number given
  324
+      #   select_second(33)
  325
+      # 
  326
+      #   # Generates a select field for seconds that defaults to the seconds for the time in my_time
  327
+      #   # that is named 'interval' rather than 'second'
  328
+      #   select_second(my_time, :field_name => 'interval')
  329
+      #
181 330
       def select_second(datetime, options = {})
182 331
         val = datetime ? (datetime.kind_of?(Fixnum) ? datetime : datetime.sec) : ''
183 332
         if options[:use_hidden]
@@ -198,6 +347,20 @@ def select_second(datetime, options = {})
198 347
       # Also can return a select tag with options by <tt>minute_step</tt> from 0 through 59 with the 00 minute selected
199 348
       # The <tt>minute</tt> can also be substituted for a minute number.
200 349
       # Override the field name using the <tt>:field_name</tt> option, 'minute' by default.
  350
+      #
  351
+      # ==== Examples
  352
+      #   my_time = Time.now + 6.hours
  353
+      #
  354
+      #   # Generates a select field for minutes that defaults to the minutes for the time in my_time
  355
+      #   select_minute(my_time)
  356
+      #
  357
+      #   # Generates a select field for minutes that defaults to the number given
  358
+      #   select_minute(14)
  359
+      # 
  360
+      #   # Generates a select field for minutes that defaults to the minutes for the time in my_time
  361
+      #   # that is named 'stride' rather than 'second'
  362
+      #   select_minute(my_time, :field_name => 'stride')
  363
+      #
201 364
       def select_minute(datetime, options = {})
202 365
         val = datetime ? (datetime.kind_of?(Fixnum) ? datetime : datetime.min) : ''
203 366
         if options[:use_hidden]
@@ -217,6 +380,20 @@ def select_minute(datetime, options = {})
217 380
       # Returns a select tag with options for each of the hours 0 through 23 with the current hour selected.
218 381
       # The <tt>hour</tt> can also be substituted for a hour number.
219 382
       # Override the field name using the <tt>:field_name</tt> option, 'hour' by default.
  383
+      #
  384
+      # ==== Examples
  385
+      #   my_time = Time.now + 6.hours
  386
+      #
  387
+      #   # Generates a select field for minutes that defaults to the minutes for the time in my_time
  388
+      #   select_minute(my_time)
  389
+      #
  390
+      #   # Generates a select field for minutes that defaults to the number given
  391
+      #   select_minute(14)
  392
+      # 
  393
+      #   # Generates a select field for minutes that defaults to the minutes for the time in my_time
  394
+      #   # that is named 'stride' rather than 'second'
  395
+      #   select_minute(my_time, :field_name => 'stride')
  396
+      #
220 397
       def select_hour(datetime, options = {})
221 398
         val = datetime ? (datetime.kind_of?(Fixnum) ? datetime : datetime.hour) : ''
222 399
         if options[:use_hidden]
@@ -236,6 +413,20 @@ def select_hour(datetime, options = {})
236 413
       # Returns a select tag with options for each of the days 1 through 31 with the current day selected.
237 414
       # The <tt>date</tt> can also be substituted for a hour number.
238 415
       # Override the field name using the <tt>:field_name</tt> option, 'day' by default.
  416
+      #
  417
+      # ==== Examples
  418
+      #   my_date = Time.today + 2.days
  419
+      #
  420
+      #   # Generates a select field for days that defaults to the day for the date in my_date
  421
+      #   select_day(my_time)
  422
+      #
  423
+      #   # Generates a select field for days that defaults to the number given
  424
+      #   select_day(5)
  425
+      # 
  426
+      #   # Generates a select field for days that defaults to the day for the date in my_date
  427
+      #   # that is named 'due' rather than 'day'
  428
+      #   select_day(my_time, :field_name => 'due')
  429
+      #
239 430
       def select_day(date, options = {})
240 431
         val = date ? (date.kind_of?(Fixnum) ? date : date.day) : ''
241 432
         if options[:use_hidden]
@@ -258,17 +449,34 @@ def select_day(date, options = {})
258 449
       # set the <tt>:use_month_numbers</tt> key in +options+ to true for this to happen. If you want both numbers and names,
259 450
       # set the <tt>:add_month_numbers</tt> key in +options+ to true. If you would prefer to show month names as abbreviations,
260 451
       # set the <tt>:use_short_month</tt> key in +options+ to true. If you want to use your own month names, set the
261  
-      # <tt>:use_month_names</tt> key in +options+ to an array of 12 month names.
  452
+      # <tt>:use_month_names</tt> key in +options+ to an array of 12 month names. Override the field name using the 
  453
+      # <tt>:field_name</tt> option, 'month' by default.
262 454
       #
263  
-      # Examples:
  455
+      # ==== Examples
  456
+      #   # Generates a select field for months that defaults to the current month that
  457
+      #   # will use keys like "January", "March".
  458
+      #   select_month(Date.today)
264 459
       #
265  
-      #   select_month(Date.today)                             # Will use keys like "January", "March"
266  
-      #   select_month(Date.today, :use_month_numbers => true) # Will use keys like "1", "3"
267  
-      #   select_month(Date.today, :add_month_numbers => true) # Will use keys like "1 - January", "3 - March"
268  
-      #   select_month(Date.today, :use_short_month => true)   # Will use keys like "Jan", "Mar"
269  
-      #   select_month(Date.today, :use_month_names => %w(Januar Februar Marts ...))   # Will use keys like "Januar", "Marts"
  460
+      #   # Generates a select field for months that defaults to the current month that
  461
+      #   # is named "start" rather than "month"
  462
+      #   select_month(Date.today, :field_name => 'start')
  463
+      #
  464
+      #   # Generates a select field for months that defaults to the current month that
  465
+      #   # will use keys like "1", "3".       
  466
+      #   select_month(Date.today, :use_month_numbers => true)
  467
+      #
  468
+      #   # Generates a select field for months that defaults to the current month that
  469
+      #   # will use keys like "1 - January", "3 - March".
  470
+      #   select_month(Date.today, :add_month_numbers => true)
  471
+      #
  472
+      #   # Generates a select field for months that defaults to the current month that
  473
+      #   # will use keys like "Jan", "Mar".
  474
+      #   select_month(Date.today, :use_short_month => true)
  475
+      #
  476
+      #   # Generates a select field for months that defaults to the current month that
  477
+      #   # will use keys like "Januar", "Marts."
  478
+      #   select_month(Date.today, :use_month_names => %w(Januar Februar Marts ...))
270 479
       #
271  
-      # Override the field name using the <tt>:field_name</tt> option, 'month' by default.
272 480
       def select_month(date, options = {})
273 481
         val = date ? (date.kind_of?(Fixnum) ? date : date.month) : ''
274 482
         if options[:use_hidden]
@@ -298,13 +506,25 @@ def select_month(date, options = {})
298 506
       # Returns a select tag with options for each of the five years on each side of the current, which is selected. The five year radius
299 507
       # can be changed using the <tt>:start_year</tt> and <tt>:end_year</tt> keys in the +options+. Both ascending and descending year
300 508
       # lists are supported by making <tt>:start_year</tt> less than or greater than <tt>:end_year</tt>. The <tt>date</tt> can also be
301  
-      # substituted for a year given as a number. Example:
  509
+      # substituted for a year given as a number.  Override the field name using the <tt>:field_name</tt> option, 'year' by default.
  510
+      #
  511
+      # ==== Examples
  512
+      #   # Generates a select field for years that defaults to the current year that
  513
+      #   # has ascending year values
  514
+      #   select_year(Date.today, :start_year => 1992, :end_year => 2007)
  515
+      #
  516
+      #   # Generates a select field for years that defaults to the current year that
  517
+      #   # is named 'birth' rather than 'year'
  518
+      #   select_year(Date.today, :field_name => 'birth')
  519
+      #
  520
+      #   # Generates a select field for years that defaults to the current year that
  521
+      #   # has descending year values
  522
+      #   select_year(Date.today, :start_year => 2005, :end_year => 1900)
302 523
       #
303  
-      #   select_year(Date.today, :start_year => 1992, :end_year => 2007)  # ascending year values
304  
-      #   select_year(Date.today, :start_year => 2005, :end_year => 1900)  # descending year values
  524
+      #   # Generates a select field for years that defaults to the year 2006 that
  525
+      #   # has ascending year values
305 526
       #   select_year(2006, :start_year => 2000, :end_year => 2010)
306 527
       #
307  
-      # Override the field name using the <tt>:field_name</tt> option, 'year' by default.
308 528
       def select_year(date, options = {})
309 529
         val = date ? (date.kind_of?(Fixnum) ? date : date.year) : ''
310 530
         if options[:use_hidden]
299  actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -3,33 +3,36 @@
3 3
 
4 4
 module ActionView
5 5
   module Helpers
6  
-    # Provides a number of methods for creating form tags that doesn't rely on conventions with an object assigned to the template like
7  
-    # FormHelper does. With the FormTagHelper, you provide the names and values yourself.
  6
+    # Provides a number of methods for creating form tags that doesn't rely on an ActiveRecord object assigned to the template like
  7
+    # FormHelper does. Instead, you provide the names and values manually.
8 8
     #
9  
-    # NOTE: The html options disabled, readonly, and multiple can all be treated as booleans. So specifying <tt>:disabled => true</tt>
10  
-    # will give <tt>disabled="disabled"</tt>.
  9
+    # NOTE: The HTML options <tt>disabled</tt>, <tt>readonly</tt>, and <tt>multiple</tt> can all be treated as booleans. So specifying 
  10
+    # <tt>:disabled => true</tt> will give <tt>disabled="disabled"</tt>.
11 11
     module FormTagHelper
12 12
       # Starts a form tag that points the action to an url configured with <tt>url_for_options</tt> just like
13 13
       # ActionController::Base#url_for. The method for the form defaults to POST.
14 14
       #
15  
-      # Examples:
16  
-      # * <tt>form_tag('/posts') => <form action="/posts" method="post"></tt>
17  
-      # * <tt>form_tag('/posts/1', :method => :put) => <form action="/posts/1" method="put"></tt>
18  
-      # * <tt>form_tag('/upload', :multipart => true) => <form action="/upload" method="post" enctype="multipart/form-data"></tt>
19  
-      # 
20  
-      # ERb example:
21  
-      #   <% form_tag '/posts' do -%>
22  
-      #     <div><%= submit_tag 'Save' %></div>
23  
-      #   <% end -%>
24  
-      #
25  
-      # Will output:
26  
-      #   <form action="/posts" method="post"><div><input type="submit" name="submit" value="Save" /></div></form>
27  
-      #
28  
-      # Options:
  15
+      # ==== Options
29 16
       # * <tt>:multipart</tt> - If set to true, the enctype is set to "multipart/form-data".
30 17
       # * <tt>:method</tt>    - The method to use when submitting the form, usually either "get" or "post".
31 18
       #                         If "put", "delete", or another verb is used, a hidden input with name _method 
32 19
       #                         is added to simulate the verb over post.
  20
+      # * A list of parameters to feed to the URL the form will be posted to.
  21
+      #
  22
+      # ==== Examples
  23
+      #   form_tag('/posts')                      
  24
+      #   # => <form action="/posts" method="post">
  25
+      #
  26
+      #   form_tag('/posts/1', :method => :put)   
  27
+      #   # => <form action="/posts/1" method="put">
  28
+      #
  29
+      #   form_tag('/upload', :multipart => true) 
  30
+      #   # => <form action="/upload" method="post" enctype="multipart/form-data">
  31
+      # 
  32
+      #   <% form_tag '/posts' do -%>
  33
+      #     <div><%= submit_tag 'Save' %></div>
  34
+      #   <% end -%>
  35
+      #   # => <form action="/posts" method="post"><div><input type="submit" name="submit" value="Save" /></div></form>
33 36
       def form_tag(url_for_options = {}, options = {}, *parameters_for_url, &block)
34 37
         html_options = html_options_for_form(url_for_options, options, *parameters_for_url)
35 38
         if block_given?
@@ -39,45 +42,101 @@ def form_tag(url_for_options = {}, options = {}, *parameters_for_url, &block)
39 42
         end
40 43
       end
41 44
 
42  
-
43 45
       # Creates a dropdown selection box, or if the <tt>:multiple</tt> option is set to true, a multiple
44 46
       # choice selection box.
45 47
       #
46 48
       # Helpers::FormOptions can be used to create common select boxes such as countries, time zones, or
47  
-      # associated records.
  49
+      # associated records. <tt>option_tags</tt> is a string containing the option tags for the select box.
  50
+      #
  51
+      # ==== Options
  52
+      # * <tt>:multiple</tt> - If set to true the selection will allow multiple choices.
  53
+      # * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
  54
+      # * Any other key creates standard HTML attributes for the tag.
48 55
       #
49  
-      # <tt>option_tags</tt> is a string containing the option tags for the select box:
50  
-      #   # Outputs <select id="people" name="people"><option>David</option></select>
  56
+      # ==== Examples
51 57
       #   select_tag "people", "<option>David</option>"
  58
+      #   # => <select id="people" name="people"><option>David</option></select>
52 59
       #
53  
-      # Options:
54  
-      # * <tt>:multiple</tt> - If set to true the selection will allow multiple choices.
  60
+      #   select_tag "count", "<option>1</option><option>2</option><option>3</option><option>4</option>"
  61
+      #   # => <select id="count" name="count"><option>1</option><option>2</option>
  62
+      #   #    <option>3</option><option>4</option></select>
  63
+      #
  64
+      #   select_tag "colors", "<option>Red</option><option>Green</option><option>Blue</option>", :multiple => true
  65
+      #   # => <select id="colors" multiple="multiple" name="colors"><option>Red</option>
  66
+      #   #    <option>Green</option><option>Blue</option></select>
  67
+      #
  68
+      #   select_tag "locations", "<option>Home</option><option selected="selected">Work</option><option>Out</option>"
  69
+      #   # => <select id="locations" name="locations"><option>Home</option><option selected='selected'>Work</option>
  70
+      #   #    <option>Out</option></select>
  71
+      #
  72
+      #   select_tag "access", "<option>Read</option><option>Write</option>", :multiple => true, :class => 'form_input'
  73
+      #   # => <select class="form_input" id="access" multiple="multiple" name="access"><option>Read</option>
  74
+      #   #    <option>Write</option></select>
  75
+      #
  76
+      #   select_tag "destination", "<option>NYC</option><option>Paris</option><option>Rome</option>", :disabled => true
  77
+      #   # => <select disabled="disabled" id="destination" name="destination"><option>NYC</option>
  78
+      #   #    <option>Paris</option><option>Rome</option></select>
55 79
       def select_tag(name, option_tags = nil, options = {})
56 80
         content_tag :select, option_tags, { "name" => name, "id" => name }.update(options.stringify_keys)
57 81
       end
58 82
 
59  
-      # Creates a standard text field.
  83
+      # Creates a standard text field; use these text fields to input smaller chunks of text like a username
  84
+      # or a search query.
60 85
       #
61  
-      # Options:
  86
+      # ==== Options
62 87
       # * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
63 88
       # * <tt>:size</tt> - The number of visible characters that will fit in the input.
64 89
       # * <tt>:maxlength</tt> - The maximum number of characters that the browser will allow the user to enter.
  90
+      # * Any other key creates standard HTML attributes for the tag.
65 91
       # 
66  
-      # A hash of standard HTML options for the tag.
  92
+      # ==== Examples
  93
+      #   text_field_tag 'name'
  94
+      #   # => <input id="name" name="name" type="text" />
  95
+      #
  96
+      #   text_field_tag 'query', 'Enter your search query here'
  97
+      #   # => <input id="query" name="query" type="text" value="Enter your search query here" />
  98
+      #
  99
+      #   text_field_tag 'request', nil, :class => 'special_input'
  100
+      #   # => <input class="special_input" id="request" name="request" type="text" />
  101
+      #
  102
+      #   text_field_tag 'address', '', :size => 75
  103
+      #   # => <input id="address" name="address" size="75" type="text" value="" />
  104
+      #
  105
+      #   text_field_tag 'zip', nil, :maxlength => 5
  106
+      #   # => <input id="zip" maxlength="5" name="zip" type="text" />
  107
+      #
  108
+      #   text_field_tag 'payment_amount', '$0.00', :disabled => true
  109
+      #   # => <input disabled="disabled" id="payment_amount" name="payment_amount" type="text" value="$0.00" />
  110
+      #
  111
+      #   text_field_tag 'ip', '0.0.0.0', :maxlength => 15, :size => 20, :class => "ip-input"
  112
+      #   # => <input class="ip-input" id="ip" maxlength="15" name="ip" size="20" type="text" value="0.0.0.0" />
67 113
       def text_field_tag(name, value = nil, options = {})
68 114
         tag :input, { "type" => "text", "name" => name, "id" => name, "value" => value }.update(options.stringify_keys)
69 115
       end
70 116
 
71  
-      # Creates a hidden field.
  117
+      # Creates a hidden form input field used to transmit data that would be lost due to HTTP's statelessness or
  118
+      # data that should be hidden from the user.
  119
+      #
  120
+      # ==== Options
  121
+      # * Creates standard HTML attributes for the tag.
  122
+      #
  123
+      # ==== Examples
  124
+      #   hidden_field_tag 'tags_list'
  125
+      #   # => <input id="tags_list" name="tags_list" type="hidden" />
72 126
       #
73  
-      # Takes the same options as text_field_tag
  127
+      #   hidden_field_tag 'token', 'VUBJKB23UIVI1UU1VOBVI@'
  128
+      #   # => <input id="token" name="token" type="hidden" value="VUBJKB23UIVI1UU1VOBVI@" />
  129
+      #
  130
+      #   hidden_field_tag 'collected_input', '', :onchange => "alert('Input collected!')"
  131
+      #   # => <input id="collected_input" name="collected_input" onchange="alert('Input collected!')" 
  132
+      #   #    type="hidden" value="" />
74 133
       def hidden_field_tag(name, value = nil, options = {})
75 134
         text_field_tag(name, value, options.stringify_keys.update("type" => "hidden"))
76 135
       end
77 136
 
78  
-      # Creates a file upload field.
  137
+      # Creates a file upload field.  If you are using file uploads then you will also need 
  138
+      # to set the multipart option for the form tag:
79 139
       #
80  
-      # If you are using file uploads then you will also need to set the multipart option for the form:
81 140
       #   <%= form_tag { :action => "post" }, { :multipart => true } %>
82 141
       #     <label for="file">File to Upload</label> <%= file_field_tag "file" %>
83 142
       #     <%= submit_tag %>
@@ -85,23 +144,93 @@ def hidden_field_tag(name, value = nil, options = {})
85 144
       #
86 145
       # The specified URL will then be passed a File object containing the selected file, or if the field 
87 146
       # was left blank, a StringIO object.
  147
+      #
  148
+      # ==== Options
  149
+      # * Creates standard HTML attributes for the tag.
  150
+      # * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
  151
+      #
  152
+      # ==== Examples
  153
+      #   file_field_tag 'attachment'
  154
+      #   # => <input id="attachment" name="attachment" type="file" />
  155
+      #
  156
+      #   file_field_tag 'avatar', :class => 'profile-input'