aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/action_view_overview.md
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikachu.com>2012-09-01 17:25:58 -0400
committerPrem Sichanugrist <s@sikac.hu>2012-09-17 15:54:22 -0400
commit872b7af337196febc516cb6218ae3d07f01a11a8 (patch)
treebc31fdc0803fff3aed26b6599cf2df7789055a41 /guides/source/action_view_overview.md
parent7bc1ca351523949f6b4ce96018e95e61cbc7719e (diff)
downloadrails-872b7af337196febc516cb6218ae3d07f01a11a8.tar.gz
rails-872b7af337196febc516cb6218ae3d07f01a11a8.tar.bz2
rails-872b7af337196febc516cb6218ae3d07f01a11a8.zip
Convert heading tags and heading section
Diffstat (limited to 'guides/source/action_view_overview.md')
-rw-r--r--guides/source/action_view_overview.md246
1 files changed, 128 insertions, 118 deletions
diff --git a/guides/source/action_view_overview.md b/guides/source/action_view_overview.md
index b22ab8c91a..1b31c129a3 100644
--- a/guides/source/action_view_overview.md
+++ b/guides/source/action_view_overview.md
@@ -1,4 +1,5 @@
-h2. Action View Overview
+Action View Overview
+====================
In this guide you will learn:
@@ -8,9 +9,10 @@ In this guide you will learn:
* What helpers are provided by Action View, and how to make your own
* How to use localized views
-endprologue.
+--------------------------------------------------------------------------------
-h3. What is Action View?
+What is Action View?
+--------------------
Action View and Action Controller are the two major components of Action Pack. In Rails, web requests are handled by Action Pack, which splits the work into a controller part (performing the logic) and a view part (rendering a template). Typically, Action Controller will be concerned with communicating with the database and performing CRUD actions where necessary. Action View is then responsible for compiling the response.
@@ -18,7 +20,8 @@ Action View templates are written using embedded Ruby in tags mingled with HTML.
NOTE. Some features of Action View are tied to Active Record, but that doesn't mean that Action View depends on Active Record. Action View is an independent package that can be used with any sort of backend.
-h3. Using Action View with Rails
+Using Action View with Rails
+----------------------------
For each controller there is an associated directory in the <tt>app/views</tt> directory which holds the template files that make up the views associated with that controller. These files are used to display the view that results from each controller action.
@@ -43,7 +46,8 @@ There is a naming convention for views in Rails. Typically, the views share thei
For example, the index controller action of the <tt>posts_controller.rb</tt> will use the <tt>index.html.erb</tt> view file in the <tt>app/views/posts</tt> directory.
The complete HTML returned to the client is composed of a combination of this ERB file, a layout template that wraps it, and all the partials that the view may reference. Later on this guide you can find a more detailed documentation of each one of this three components.
-h3. Using Action View outside of Rails
+Using Action View outside of Rails
+----------------------------------
Action View works well with Action Record, but it can also be used with other Ruby tools. We can demonstrate this by creating a small "Rack":http://rack.rubyforge.org/ application that includes Action View functionality. This may be useful, for example, if you'd like access to Action View's helpers in a Rack application.
@@ -111,18 +115,19 @@ Once the application is running, you can see Sinatra and Action View working tog
TODO needs a screenshot? I have one - not sure where to put it.
-h3. Templates, Partials and Layouts
+Templates, Partials and Layouts
+-------------------------------
As mentioned before, the final HTML output is a composition of three Rails elements: +Templates+, +Partials+ and +Layouts+.
Find below a brief overview of each one of them.
-h4. Templates
+### Templates
Action View templates can be written in several ways. If the template file has a <tt>.erb</tt> extension then it uses a mixture of ERB (included in Ruby) and HTML. If the template file has a <tt>.builder</tt> extension then a fresh instance of <tt>Builder::XmlMarkup</tt> library is used.
Rails supports multiple template systems and uses a file extension to distinguish amongst them. For example, an HTML file using the ERB template system will have <tt>.html.erb</tt> as a file extension.
-h5. ERB
+#### ERB
Within an ERB template Ruby code can be included using both +<% %>+ and +<%= %>+ tags. The +<% %>+ are used to execute Ruby code that does not return anything, such as conditions, loops or blocks, and the +<%= %>+ tags are used when you want output.
@@ -144,7 +149,7 @@ Hi, Mr. <% puts "Frodo" %>
To suppress leading and trailing whitespaces, you can use +<%-+ +-%>+ interchangeably with +<%+ and +%>+.
-h5. Builder
+#### Builder
Builder templates are a more programmatic alternative to ERB. They are especially useful for generating XML content. An XmlMarkup object named +xml+ is automatically made available to templates with a <tt>.builder</tt> extension.
@@ -209,15 +214,15 @@ xml.rss("version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do
end
```
-h5. Template Caching
+#### Template Caching
By default, Rails will compile each template to a method in order to render it. When you alter a template, Rails will check the file's modification time and recompile it in development mode.
-h4. Partials
+### Partials
Partial templates – usually just called "partials" – are another device for breaking the rendering process into more manageable chunks. With a partial, you can move the code for rendering a particular piece of a response to its own file.
-h5. Naming Partials
+#### Naming Partials
To render a partial as part of a view, you use the +render+ method within the view:
@@ -233,7 +238,7 @@ This will render a file named +_menu.html.erb+ at that point within the view is
That code will pull in the partial from +app/views/shared/_menu.html.erb+.
-h5. Using Partials to simplify Views
+#### Using Partials to simplify Views
One way to use partials is to treat them as the equivalent of subroutines: as a way to move details out of a view so that you can grasp what's going on more easily. For example, you might have a view that looked like this:
@@ -252,7 +257,7 @@ One way to use partials is to treat them as the equivalent of subroutines: as a
Here, the +_ad_banner.html.erb+ and +_footer.html.erb+ partials could contain content that is shared among many pages in your application. You don't need to see the details of these sections when you're concentrating on a particular page.
-h5. The :as and :object options
+#### The :as and :object options
By default <tt>ActionView::Partials::PartialRenderer</tt> has its object in a local variable with the same name as the template. So, given
@@ -288,7 +293,7 @@ you'd do:
The <tt>:object</tt> and <tt>:as</tt> options can be used together.
-h5. Rendering Collections
+#### Rendering Collections
The example of partial use describes a familiar pattern where a template needs to iterate over an array and render a sub template for each of the elements. This pattern has been implemented as a single method that accepts an array and renders a partial by the same name as the elements contained within.
So the three-lined example for rendering all the products can be rewritten with a single line:
@@ -307,7 +312,7 @@ You can use a shorthand syntax for rendering collections. Assuming @products is
Rails determines the name of the partial to use by looking at the model name in the collection. In fact, you can even create a heterogeneous collection and render it this way, and Rails will choose the proper partial for each member of the collection.
-h5. Spacer Templates
+#### Spacer Templates
You can also specify a second partial to be rendered between instances of the main partial by using the +:spacer_template+ option:
@@ -317,15 +322,17 @@ You can also specify a second partial to be rendered between instances of the ma
Rails will render the +_product_ruler+ partial (with no data passed in to it) between each pair of +_product+ partials.
-h4. Layouts
+### Layouts
TODO...
-h3. Using Templates, Partials and Layouts in "The Rails Way"
+Using Templates, Partials and Layouts in "The Rails Way"
+--------------------------------------------------------
TODO...
-h3. Partial Layouts
+Partial Layouts
+---------------
Partials can have their own layouts applied to them. These layouts are different than the ones that are specified globally for the entire action, but they work in a similar fashion.
@@ -389,19 +396,21 @@ You can also render a block of code within a partial layout instead of calling +
If we're using the same +box+ partial from above, his would produce the same output as the previous example.
-h3. View Paths
+View Paths
+----------
TODO...
-h3. Overview of all the helpers provided by Action View
+Overview of all the helpers provided by Action View
+---------------------------------------------------
The following is only a brief overview summary of the helpers available in Action View. It's recommended that you review the API Documentation, which covers all of the helpers in more detail, but this should serve as a good starting point.
-h4. ActiveRecordHelper
+### ActiveRecordHelper
The Active Record Helper makes it easier to create forms for records kept in instance variables. You may also want to review the "Rails Form helpers guide":form_helpers.html.
-h5. error_message_on
+#### error_message_on
Returns a string containing the error message attached to the method on the object if one exists.
@@ -409,7 +418,7 @@ Returns a string containing the error message attached to the method on the obje
error_message_on "post", "title"
```
-h5. error_messages_for
+#### error_messages_for
Returns a string with a DIV containing all of the error messages for the objects located as instance variables by the names given.
@@ -417,7 +426,7 @@ Returns a string with a DIV containing all of the error messages for the objects
error_messages_for "post"
```
-h5. form
+#### form
Returns a form with inputs for all attributes of the specified Active Record object. For example, let's say we have a +@post+ with attributes named +title+ of type +String+ and +body+ of type +Text+. Calling +form+ would produce a form to creating a new post with inputs for those attributes.
@@ -441,7 +450,7 @@ form("post")
Typically, +form_for+ is used instead of +form+ because it doesn't automatically include all of the model's attributes.
-h5. input
+#### input
Returns a default input tag for the type of object returned by the method.
@@ -452,11 +461,11 @@ input("post", "title") # =>
<input id="post_title" name="post[title]" type="text" value="Hello World" />
```
-h4. RecordTagHelper
+### RecordTagHelper
This module provides methods for generating container tags, such as +div+, for your record. This is the recommended way of creating a container for render your Active Record object, as it adds an appropriate class and id attributes to that container. You can then refer to those containers easily by following the convention, instead of having to think about which class or id attribute you should use.
-h5. content_tag_for
+#### content_tag_for
Renders a container tag that relates to your Active Record Object.
@@ -511,7 +520,7 @@ Will generate this HTML output:
</tr>
```
-h5. div_for
+#### div_for
This is actually a convenient method which calls +content_tag_for+ internally with +:div+ as the tag name. You can pass either an Active Record object or a collection of objects. For example:
@@ -529,7 +538,7 @@ Will generate this HTML output:
</div>
```
-h4. AssetTagHelper
+### AssetTagHelper
This module provides methods for generating HTML that links views to assets such as images, JavaScript files, stylesheets, and feeds.
@@ -540,7 +549,7 @@ config.action_controller.asset_host = "assets.example.com"
image_tag("rails.png") # => <img src="http://assets.example.com/images/rails.png" alt="Rails" />
```
-h5. register_javascript_expansion
+#### register_javascript_expansion
Register one or more JavaScript files to be included when symbol is passed to javascript_include_tag. This method is typically intended to be called from plugin initialization to register JavaScript files that the plugin installed in +vendor/assets/javascripts+.
@@ -553,7 +562,7 @@ javascript_include_tag :monkey # =>
<script src="/assets/tail.js"></script>
```
-h5. register_stylesheet_expansion
+#### register_stylesheet_expansion
Register one or more stylesheet files to be included when symbol is passed to +stylesheet_link_tag+. This method is typically intended to be called from plugin initialization to register stylesheet files that the plugin installed in +vendor/assets/stylesheets+.
@@ -566,7 +575,7 @@ stylesheet_link_tag :monkey # =>
<link href="/assets/tail.css" media="screen" rel="stylesheet" />
```
-h5. auto_discovery_link_tag
+#### auto_discovery_link_tag
Returns a link tag that browsers and news readers can use to auto-detect an RSS or Atom feed.
@@ -575,7 +584,7 @@ auto_discovery_link_tag(:rss, "http://www.example.com/feed.rss", {:title => "RSS
<link rel="alternate" type="application/rss+xml" title="RSS Feed" href="http://www.example.com/feed" />
```
-h5. image_path
+#### image_path
Computes the path to an image asset in the +app/assets/images+ directory. Full paths from the document root will be passed through. Used internally by +image_tag+ to build the image path.
@@ -589,7 +598,7 @@ Fingerprint will be added to the filename if config.assets.digest is set to true
image_path("edit.png") # => /assets/edit-2d1a2db63fc738690021fedb5a65b68e.png
```
-h5. image_url
+#### image_url
Computes the url to an image asset in the +app/asset/images+ directory. This will call +image_path+ internally and merge with your current host or your asset host.
@@ -597,7 +606,7 @@ Computes the url to an image asset in the +app/asset/images+ directory. This wil
image_url("edit.png") # => http://www.example.com/assets/edit.png
```
-h5. image_tag
+#### image_tag
Returns an html image tag for the source. The source can be a full path or a file that exists in your +app/assets/images+ directory.
@@ -605,7 +614,7 @@ Returns an html image tag for the source. The source can be a full path or a fil
image_tag("icon.png") # => <img src="/assets/icon.png" alt="Icon" />
```
-h5. javascript_include_tag
+#### javascript_include_tag
Returns an html script tag for each of the sources provided. You can pass in the filename (+.js+ extension is optional) of JavaScript files that exist in your +app/assets/javascripts+ directory for inclusion into the current page or you can pass the full path relative to your document root.
@@ -632,7 +641,7 @@ javascript_include_tag :all, :cache => true # =>
<script src="/javascripts/all.js"></script>
```
-h5. javascript_path
+#### javascript_path
Computes the path to a JavaScript asset in the +app/assets/javascripts+ directory. If the source filename has no extension, +.js+ will be appended. Full paths from the document root will be passed through. Used internally by +javascript_include_tag+ to build the script path.
@@ -640,7 +649,7 @@ Computes the path to a JavaScript asset in the +app/assets/javascripts+ director
javascript_path "common" # => /assets/common.js
```
-h5. javascript_url
+#### javascript_url
Computes the url to a JavaScript asset in the +app/assets/javascripts+ directory. This will call +javascript_path+ internally and merge with your current host or your asset host.
@@ -648,7 +657,7 @@ Computes the url to a JavaScript asset in the +app/assets/javascripts+ directory
javascript_url "common" # => http://www.example.com/assets/common.js
```
-h5. stylesheet_link_tag
+#### stylesheet_link_tag
Returns a stylesheet link tag for the sources specified as arguments. If you don't specify an extension, +.css+ will be appended automatically.
@@ -669,7 +678,7 @@ stylesheet_link_tag :all, :cache => true
# => <link href="/assets/all.css" media="screen" rel="stylesheet" />
```
-h5. stylesheet_path
+#### stylesheet_path
Computes the path to a stylesheet asset in the +app/assets/stylesheets+ directory. If the source filename has no extension, .css will be appended. Full paths from the document root will be passed through. Used internally by stylesheet_link_tag to build the stylesheet path.
@@ -677,7 +686,7 @@ Computes the path to a stylesheet asset in the +app/assets/stylesheets+ director
stylesheet_path "application" # => /assets/application.css
```
-h5. stylesheet_url
+#### stylesheet_url
Computes the url to a stylesheet asset in the +app/assets/stylesheets+ directory. This will call +stylesheet_path+ internally and merge with your current host or your asset host.
@@ -685,9 +694,9 @@ Computes the url to a stylesheet asset in the +app/assets/stylesheets+ directory
stylesheet_url "application" # => http://www.example.com/assets/application.css
```
-h4. AtomFeedHelper
+### AtomFeedHelper
-h5. atom_feed
+#### atom_feed
This helper makes building an Atom feed easy. Here's a full usage example:
@@ -730,9 +739,9 @@ atom_feed do |feed|
end
```
-h4. BenchmarkHelper
+### BenchmarkHelper
-h5. benchmark
+#### benchmark
Allows you to measure the execution time of a block in a template and records the result to the log. Wrap this block around expensive operations or possible bottlenecks to get a time reading for the operation.
@@ -744,9 +753,9 @@ Allows you to measure the execution time of a block in a template and records th
This would add something like "Process data files (0.34523)" to the log, which you can then use to compare timings when optimizing your code.
-h4. CacheHelper
+### CacheHelper
-h5. cache
+#### cache
A method for caching fragments of a view rather than an entire action or page. This technique is useful caching pieces like menus, lists of news topics, static HTML fragments, and so on. This method takes a block that contains the content you wish to cache. See +ActionController::Caching::Fragments+ for more information.
@@ -756,9 +765,9 @@ A method for caching fragments of a view rather than an entire action or page. T
<% end %>
```
-h4. CaptureHelper
+### CaptureHelper
-h5. capture
+#### capture
The +capture+ method allows you to extract part of a template into a variable. You can then use this variable anywhere in your templates or layout.
@@ -781,7 +790,7 @@ The captured variable can then be used anywhere else.
</html>
```
-h5. content_for
+#### content_for
Calling +content_for+ stores a block of markup in an identifier for later use. You can make subsequent calls to the stored content in other templates or the layout by passing the identifier as an argument to +yield+.
@@ -811,9 +820,9 @@ For example, let's say we have a standard application layout, but also a special
<% end %>
```
-h4. DateHelper
+### DateHelper
-h5. date_select
+#### date_select
Returns a set of select tags (one for year, month, and day) pre-selected for accessing a specified date-based attribute.
@@ -821,7 +830,7 @@ Returns a set of select tags (one for year, month, and day) pre-selected for acc
date_select("post", "published_on")
```
-h5. datetime_select
+#### datetime_select
Returns a set of select tags (one for year, month, day, hour, and minute) pre-selected for accessing a specified datetime-based attribute.
@@ -829,7 +838,7 @@ Returns a set of select tags (one for year, month, day, hour, and minute) pre-se
datetime_select("post", "published_on")
```
-h5. distance_of_time_in_words
+#### distance_of_time_in_words
Reports the approximate distance in time between two Time or Date objects or integers as seconds. Set +include_seconds+ to true if you want more detailed approximations.
@@ -838,7 +847,7 @@ distance_of_time_in_words(Time.now, Time.now + 15.seconds) # => less than
distance_of_time_in_words(Time.now, Time.now + 15.seconds, :include_seconds => true) # => less than 20 seconds
```
-h5. select_date
+#### select_date
Returns a set of html select-tags (one for year, month, and day) pre-selected with the +date+ provided.
@@ -850,7 +859,7 @@ select_date(Time.today + 6.days)
select_date()
```
-h5. select_datetime
+#### select_datetime
Returns a set of html select-tags (one for year, month, day, hour, and minute) pre-selected with the +datetime+ provided.
@@ -862,7 +871,7 @@ select_datetime(Time.now + 4.days)
select_datetime()
```
-h5. select_day
+#### select_day
Returns a select tag with options for each of the days 1 through 31 with the current day selected.
@@ -874,7 +883,7 @@ select_day(Time.today + 2.days)
select_day(5)
```
-h5. select_hour
+#### select_hour
Returns a select tag with options for each of the hours 0 through 23 with the current hour selected.
@@ -883,7 +892,7 @@ Returns a select tag with options for each of the hours 0 through 23 with the cu
select_minute(Time.now + 6.hours)
```
-h5. select_minute
+#### select_minute
Returns a select tag with options for each of the minutes 0 through 59 with the current minute selected.
@@ -892,7 +901,7 @@ Returns a select tag with options for each of the minutes 0 through 59 with the
select_minute(Time.now + 6.hours)
```
-h5. select_month
+#### select_month
Returns a select tag with options for each of the months January through December with the current month selected.
@@ -901,7 +910,7 @@ Returns a select tag with options for each of the months January through Decembe
select_month(Date.today)
```
-h5. select_second
+#### select_second
Returns a select tag with options for each of the seconds 0 through 59 with the current second selected.
@@ -910,7 +919,7 @@ Returns a select tag with options for each of the seconds 0 through 59 with the
select_second(Time.now + 16.minutes)
```
-h5. select_time
+#### select_time
Returns a set of html select-tags (one for hour and minute).
@@ -919,7 +928,7 @@ Returns a set of html select-tags (one for hour and minute).
select_time(Time.now)
```
-h5. select_year
+#### select_year
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 can be changed using the +:start_year+ and +:end_year+ keys in the +options+.
@@ -931,7 +940,7 @@ select_year(Date.today)
select_year(Date.today, :start_year => 1900, :end_year => 2009)
```
-h5. time_ago_in_words
+#### time_ago_in_words
Like +distance_of_time_in_words+, but where +to_time+ is fixed to +Time.now+.
@@ -939,7 +948,7 @@ Like +distance_of_time_in_words+, but where +to_time+ is fixed to +Time.now+.
time_ago_in_words(3.minutes.from_now) # => 3 minutes
```
-h5. time_select
+#### time_select
Returns a set of select tags (one for hour, minute and optionally second) pre-selected for accessing a specified time-based attribute. The selects are prepared for multi-parameter assignment to an Active Record object.
@@ -948,7 +957,7 @@ Returns a set of select tags (one for hour, minute and optionally second) pre-se
time_select("order", "submitted")
```
-h4. DebugHelper
+### DebugHelper
Returns a +pre+ tag that has object dumped by YAML. This creates a very readable way to inspect an object.
@@ -968,7 +977,7 @@ third:
</pre>
```
-h4. FormHelper
+### FormHelper
Form helpers are designed to make working with models much easier compared to using just standard HTML elements by providing a set of methods for creating forms based on your models. This helper generates the HTML for forms, providing a method for each sort of input (e.g., text, password, select, and so on). When the form is submitted (i.e., when the user hits the submit button or form.submit is called via JavaScript), the form inputs will be bundled into the params object and passed back to the controller.
@@ -1003,7 +1012,7 @@ The params object created when this form is submitted would look like:
The params hash has a nested person value, which can therefore be accessed with params[:person] in the controller.
-h5. check_box
+#### check_box
Returns a checkbox tag tailored for accessing a specified attribute.
@@ -1014,7 +1023,7 @@ check_box("post", "validated")
# <input name="post[validated]" type="hidden" value="0" />
```
-h5. fields_for
+#### fields_for
Creates a scope around a specific model object like form_for, but doesn't create the form tags themselves. This makes fields_for suitable for specifying additional model objects in the same form:
@@ -1029,7 +1038,7 @@ Creates a scope around a specific model object like form_for, but doesn't create
<% end %>
```
-h5. file_field
+#### file_field
Returns a file upload input tag tailored for accessing a specified attribute.
@@ -1038,7 +1047,7 @@ file_field(:user, :avatar)
# => <input type="file" id="user_avatar" name="user[avatar]" />
```
-h5. form_for
+#### form_for
Creates a form and a scope around a specific model object that is used as a base for questioning about values for the fields.
@@ -1051,7 +1060,7 @@ Creates a form and a scope around a specific model object that is used as a base
<% end %>
```
-h5. hidden_field
+#### hidden_field
Returns a hidden input tag tailored for accessing a specified attribute.
@@ -1060,7 +1069,7 @@ hidden_field(:user, :token)
# => <input type="hidden" id="user_token" name="user[token]" value="#{@user.token}" />
```
-h5. label
+#### label
Returns a label tag tailored for labelling an input field for a specified attribute.
@@ -1069,7 +1078,7 @@ label(:post, :title)
# => <label for="post_title">Title</label>
```
-h5. password_field
+#### password_field
Returns an input tag of the "password" type tailored for accessing a specified attribute.
@@ -1078,7 +1087,7 @@ password_field(:login, :pass)
# => <input type="text" id="login_pass" name="login[pass]" value="#{@login.pass}" />
```
-h5. radio_button
+#### radio_button
Returns a radio button tag for accessing a specified attribute.
@@ -1090,7 +1099,7 @@ radio_button("post", "category", "java")
# <input type="radio" id="post_category_java" name="post[category]" value="java" />
```
-h5. text_area
+#### text_area
Returns a textarea opening and closing tag set tailored for accessing a specified attribute.
@@ -1101,7 +1110,7 @@ text_area(:comment, :text, :size => "20x30")
# </textarea>
```
-h5. text_field
+#### text_field
Returns an input tag of the "text" type tailored for accessing a specified attribute.
@@ -1110,11 +1119,11 @@ text_field(:post, :title)
# => <input type="text" id="post_title" name="post[title]" value="#{@post.title}" />
```
-h4. FormOptionsHelper
+### FormOptionsHelper
Provides a number of methods for turning different kinds of containers into a set of option tags.
-h5. collection_select
+#### collection_select
Returns +select+ and +option+ tags for the collection of existing return values of +method+ for +object+'s class.
@@ -1150,7 +1159,7 @@ If <tt>@post.author_id</tt> is 1, this would return:
</select>
```
-h5. collection_radio_buttons
+#### collection_radio_buttons
Returns +radio_button+ tags for the collection of existing return values of +method+ for +object+'s class.
@@ -1186,7 +1195,7 @@ If <tt>@post.author_id</tt> is 1, this would return:
<label for="post_author_id_3">M. Clark</label>
```
-h5. collection_check_boxes
+#### collection_check_boxes
Returns +check_box+ tags for the collection of existing return values of +method+ for +object+'s class.
@@ -1223,15 +1232,15 @@ If <tt>@post.author_ids</tt> is <tt><notextile>[1]</notextile></tt>, this would
<input name="post[author_ids][]" type="hidden" value="" />
```
-h5. country_options_for_select
+#### country_options_for_select
Returns a string of option tags for pretty much any country in the world.
-h5. country_select
+#### country_select
Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags.
-h5. option_groups_from_collection_for_select
+#### option_groups_from_collection_for_select
Returns a string of +option+ tags, like +options_from_collection_for_select+, but groups them by +optgroup+ tags based on the object relationships of the arguments.
@@ -1273,7 +1282,7 @@ Possible output:
Note: Only the +optgroup+ and +option+ tags are returned, so you still have to wrap the output in an appropriate +select+ tag.
-h5. options_for_select
+#### options_for_select
Accepts a container (hash, array, enumerable, your type) and returns a string of option tags.
@@ -1284,7 +1293,7 @@ options_for_select([ "VISA", "MasterCard" ])
Note: Only the +option+ tags are returned, you have to wrap this call in a regular HTML +select+ tag.
-h5. options_from_collection_for_select
+#### options_from_collection_for_select
Returns a string of option tags that have been compiled by iterating over the +collection+ and assigning the result of a call to the +value_method+ as the option value and the +text_method+ as the option text.
@@ -1301,7 +1310,7 @@ options_from_collection_for_select(@project.people, "id", "name")
Note: Only the +option+ tags are returned, you have to wrap this call in a regular HTML +select+ tag.
-h5. select
+#### select
Create a select tag and a series of contained option tags for the provided object and method.
@@ -1322,11 +1331,11 @@ If <tt>@post.person_id</tt> is 1, this would become:
</select>
```
-h5. time_zone_options_for_select
+#### time_zone_options_for_select
Returns a string of option tags for pretty much any time zone in the world.
-h5. time_zone_select
+#### time_zone_select
Return select and option tags for the given object and method, using +time_zone_options_for_select+ to generate the list of option tags.
@@ -1334,11 +1343,11 @@ Return select and option tags for the given object and method, using +time_zone_
time_zone_select( "user", "time_zone")
```
-h4. FormTagHelper
+### FormTagHelper
Provides a number of methods for creating form tags that doesn't rely on an Active Record object assigned to the template like FormHelper does. Instead, you provide the names and values manually.
-h5. check_box_tag
+#### check_box_tag
Creates a check box form input tag.
@@ -1347,7 +1356,7 @@ check_box_tag 'accept'
# => <input id="accept" name="accept" type="checkbox" value="1" />
```
-h5. field_set_tag
+#### field_set_tag
Creates a field set for grouping HTML form elements.
@@ -1358,7 +1367,7 @@ Creates a field set for grouping HTML form elements.
# => <fieldset><p><input id="name" name="name" type="text" /></p></fieldset>
```
-h5. file_field_tag
+#### file_field_tag
Creates a file upload field.
@@ -1378,7 +1387,7 @@ file_field_tag 'attachment'
# => <input id="attachment" name="attachment" type="file" />
```
-h5. form_tag
+#### form_tag
Starts a form tag that points the action to an url configured with +url_for_options+ just like +ActionController::Base#url_for+.
@@ -1389,7 +1398,7 @@ Starts a form tag that points the action to an url configured with +url_for_opti
# => <form action="/posts" method="post"><div><input type="submit" name="submit" value="Save" /></div></form>
```
-h5. hidden_field_tag
+#### hidden_field_tag
Creates a hidden form input field used to transmit data that would be lost due to HTTP's statelessness or data that should be hidden from the user.
@@ -1398,7 +1407,7 @@ hidden_field_tag 'token', 'VUBJKB23UIVI1UU1VOBVI@'
# => <input id="token" name="token" type="hidden" value="VUBJKB23UIVI1UU1VOBVI@" />
```
-h5. image_submit_tag
+#### image_submit_tag
Displays an image which when clicked will submit the form.
@@ -1407,7 +1416,7 @@ image_submit_tag("login.png")
# => <input src="/images/login.png" type="image" />
```
-h5. label_tag
+#### label_tag
Creates a label field.
@@ -1416,7 +1425,7 @@ label_tag 'name'
# => <label for="name">Name</label>
```
-h5. password_field_tag
+#### password_field_tag
Creates a password field, a masked text field that will hide the users input behind a mask character.
@@ -1425,7 +1434,7 @@ password_field_tag 'pass'
# => <input id="pass" name="pass" type="password" />
```
-h5. radio_button_tag
+#### radio_button_tag
Creates a radio button; use groups of radio buttons named the same to allow users to select from a group of options.
@@ -1434,7 +1443,7 @@ radio_button_tag 'gender', 'male'
# => <input id="gender_male" name="gender" type="radio" value="male" />
```
-h5. select_tag
+#### select_tag
Creates a dropdown selection box.
@@ -1443,7 +1452,7 @@ select_tag "people", "<option>David</option>"
# => <select id="people" name="people"><option>David</option></select>
```
-h5. submit_tag
+#### submit_tag
Creates a submit button with the text provided as the caption.
@@ -1452,7 +1461,7 @@ submit_tag "Publish this post"
# => <input name="commit" type="submit" value="Publish this post" />
```
-h5. text_area_tag
+#### text_area_tag
Creates a text input area; use a textarea for longer text inputs such as blog posts or descriptions.
@@ -1461,7 +1470,7 @@ text_area_tag 'post'
# => <textarea id="post" name="post"></textarea>
```
-h5. text_field_tag
+#### text_field_tag
Creates a standard text field; use these text fields to input smaller chunks of text like a username or a search query.
@@ -1470,11 +1479,11 @@ text_field_tag 'name'
# => <input id="name" name="name" type="text" />
```
-h4. JavaScriptHelper
+### JavaScriptHelper
Provides functionality for working with JavaScript in your views.
-h5. button_to_function
+#### button_to_function
Returns a button that'll trigger a JavaScript function using the onclick handler. Examples:
@@ -1486,15 +1495,15 @@ button_to_function "Details" do |page|
end
```
-h5. define_javascript_functions
+#### define_javascript_functions
Includes the Action Pack JavaScript libraries inside a single +script+ tag.
-h5. escape_javascript
+#### escape_javascript
Escape carrier returns and single and double quotes for JavaScript segments.
-h5. javascript_tag
+#### javascript_tag
Returns a JavaScript tag wrapping the provided code.
@@ -1510,7 +1519,7 @@ alert('All is good')
</script>
```
-h5. link_to_function
+#### link_to_function
Returns a link that will trigger a JavaScript function using the onclick handler and return false after the fact.
@@ -1519,11 +1528,11 @@ link_to_function "Greeting", "alert('Hello world!')"
# => <a onclick="alert('Hello world!'); return false;" href="#">Greeting</a>
```
-h4. NumberHelper
+### NumberHelper
Provides methods for converting numbers into formatted strings. Methods are provided for phone numbers, currency, percentage, precision, positional notation, and file size.
-h5. number_to_currency
+#### number_to_currency
Formats a number into a currency string (e.g., $13.65).
@@ -1531,7 +1540,7 @@ Formats a number into a currency string (e.g., $13.65).
number_to_currency(1234567890.50) # => $1,234,567,890.50
```
-h5. number_to_human_size
+#### number_to_human_size
Formats the bytes in size into a more understandable representation; useful for reporting file sizes to users.
@@ -1540,7 +1549,7 @@ number_to_human_size(1234) # => 1.2 KB
number_to_human_size(1234567) # => 1.2 MB
```
-h5. number_to_percentage
+#### number_to_percentage
Formats a number as a percentage string.
@@ -1548,7 +1557,7 @@ Formats a number as a percentage string.
number_to_percentage(100, :precision => 0) # => 100%
```
-h5. number_to_phone
+#### number_to_phone
Formats a number into a US phone number.
@@ -1556,7 +1565,7 @@ Formats a number into a US phone number.
number_to_phone(1235551234) # => 123-555-1234
```
-h5. number_with_delimiter
+#### number_with_delimiter
Formats a number with grouped thousands using a delimiter.
@@ -1564,7 +1573,7 @@ Formats a number with grouped thousands using a delimiter.
number_with_delimiter(12345678) # => 12,345,678
```
-h5. number_with_precision
+#### number_with_precision
Formats a number with the specified level of +precision+, which defaults to 3.
@@ -1573,7 +1582,8 @@ number_with_precision(111.2345) # => 111.235
number_with_precision(111.2345, 2) # => 111.23
```
-h3. Localized Views
+Localized Views
+---------------
Action View has the ability render different templates depending on the current locale.