Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 8b99df826c3b6cf56a1caaae5f931d50 > files > 719

ruby-actionpack-2.3.4-1mdv2010.0.noarch.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActionView::Helpers::AssetTagHelper</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActionView::Helpers::AssetTagHelper</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/lib/action_view/helpers/asset_tag_helper_rb.html">
                lib/action_view/helpers/asset_tag_helper.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
This module provides methods for generating HTML that links views to assets
such as images, javascripts, stylesheets, and feeds. These methods do not
verify the assets exist before linking to them:
</p>
<pre>
  image_tag(&quot;rails.png&quot;)
  # =&gt; &lt;img alt=&quot;Rails src=&quot;/images/rails.png?1230601161&quot; /&gt;
  stylesheet_link_tag(&quot;application&quot;)
  # =&gt; &lt;link href=&quot;/stylesheets/application.css?1232285206&quot; media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
</pre>
<h3>Using asset hosts</h3>
<p>
By default, Rails links to these assets on the current host in the public
folder, but you can direct Rails to link to assets from a dedicated asset
server by setting ActionController::Base.asset_host in the application
configuration, typically in <tt>config/environments/production.rb</tt>. For
example, you&#8216;d define <tt>assets.example.com</tt> to be your asset
host this way:
</p>
<pre>
  ActionController::Base.asset_host = &quot;assets.example.com&quot;
</pre>
<p>
Helpers take that into account:
</p>
<pre>
  image_tag(&quot;rails.png&quot;)
  # =&gt; &lt;img alt=&quot;Rails&quot; src=&quot;http://assets.example.com/images/rails.png?1230601161&quot; /&gt;
  stylesheet_link_tag(&quot;application&quot;)
  # =&gt; &lt;link href=&quot;http://assets.example.com/stylesheets/application.css?1232285206&quot; media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
</pre>
<p>
Browsers typically open at most two simultaneous connections to a single
host, which means your assets often have to wait for other assets to finish
downloading. You can alleviate this by using a <tt>%d</tt> wildcard in the
<tt>asset_host</tt>. For example, &quot;assets%d.example.com&quot;. If that
wildcard is present Rails distributes asset requests among the
corresponding four hosts &quot;assets0.example.com&quot;, &#8230;,
&quot;assets3.example.com&quot;. With this trick browsers will open eight
simultaneous connections rather than two.
</p>
<pre>
  image_tag(&quot;rails.png&quot;)
  # =&gt; &lt;img alt=&quot;Rails&quot; src=&quot;http://assets0.example.com/images/rails.png?1230601161&quot; /&gt;
  stylesheet_link_tag(&quot;application&quot;)
  # =&gt; &lt;link href=&quot;http://assets2.example.com/stylesheets/application.css?1232285206&quot; media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
</pre>
<p>
To do this, you can either setup four actual hosts, or you can use wildcard
DNS to CNAME the wildcard to a single asset host. You can read more about
setting up your DNS CNAME records from your ISP.
</p>
<p>
Note: This is purely a browser performance optimization and is not meant
for server load balancing. See <a
href="http://www.die.net/musings/page_load_time">www.die.net/musings/page_load_time</a>/
for background.
</p>
<p>
Alternatively, you can exert more control over the asset host by setting
<tt>asset_host</tt> to a proc like this:
</p>
<pre>
  ActionController::Base.asset_host = Proc.new { |source|
    &quot;http://assets#{rand(2) + 1}.example.com&quot;
  }
  image_tag(&quot;rails.png&quot;)
  # =&gt; &lt;img alt=&quot;Rails&quot; src=&quot;http://assets0.example.com/images/rails.png?1230601161&quot; /&gt;
  stylesheet_link_tag(&quot;application&quot;)
  # =&gt; &lt;link href=&quot;http://assets1.example.com/stylesheets/application.css?1232285206&quot; media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
</pre>
<p>
The example above generates &quot;<a
href="http://assets1.example.com">assets1.example.com</a>&quot; and
&quot;<a href="http://assets2.example.com">assets2.example.com</a>&quot;
randomly. This option is useful for example if you need fewer/more than
four hosts, custom host names, etc.
</p>
<p>
As you see the proc takes a <tt>source</tt> parameter. That&#8216;s a
string with the absolute path of the asset with any extensions and
timestamps in place, for example &quot;/images/rails.png?1230601161&quot;.
</p>
<pre>
   ActionController::Base.asset_host = Proc.new { |source|
     if source.starts_with?('/images')
       &quot;http://images.example.com&quot;
     else
       &quot;http://assets.example.com&quot;
     end
   }
  image_tag(&quot;rails.png&quot;)
  # =&gt; &lt;img alt=&quot;Rails&quot; src=&quot;http://images.example.com/images/rails.png?1230601161&quot; /&gt;
  stylesheet_link_tag(&quot;application&quot;)
  # =&gt; &lt;link href=&quot;http://assets.example.com/stylesheets/application.css?1232285206&quot; media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
</pre>
<p>
Alternatively you may ask for a second parameter <tt>request</tt>. That one
is particularly useful for serving assets from an SSL-protected page. The
example proc below disables asset hosting for HTTPS connections, while
still sending assets for plain HTTP requests from asset hosts. If you
don&#8216;t have SSL certificates for each of the asset hosts this
technique allows you to avoid warnings in the client about mixed media.
</p>
<pre>
  ActionController::Base.asset_host = Proc.new { |source, request|
    if request.ssl?
      &quot;#{request.protocol}#{request.host_with_port}&quot;
    else
      &quot;#{request.protocol}assets.example.com&quot;
    end
  }
</pre>
<p>
You can also implement a custom asset host object that responds to
<tt>call</tt> and takes either one or two parameters just like the proc.
</p>
<pre>
  config.action_controller.asset_host = AssetHostingWithMinimumSsl.new(
    &quot;http://asset%d.example.com&quot;, &quot;https://asset1.example.com&quot;
  )
</pre>
<h3>Using asset timestamps</h3>
<p>
By default, Rails appends asset&#8216;s timestamps to all asset paths. This
allows you to set a cache-expiration date for the asset far into the
future, but still be able to instantly invalidate it by simply updating the
file (and hence updating the timestamp, which then updates the URL as the
timestamp is part of that, which in turn busts the cache).
</p>
<p>
It&#8216;s the responsibility of the web server you use to set the
far-future expiration date on cache assets that you need to take advantage
of this feature. Here&#8216;s an example for Apache:
</p>
<pre>
  # Asset Expiration
  ExpiresActive On
  &lt;FilesMatch &quot;\.(ico|gif|jpe?g|png|js|css)$&quot;&gt;
    ExpiresDefault &quot;access plus 1 year&quot;
  &lt;/FilesMatch&gt;
</pre>
<p>
Also note that in order for this to work, all your application servers must
return the same timestamps. This means that they must have their clocks
synchronized. If one of them drifts out of sync, you&#8216;ll see different
timestamps at random and the cache won&#8216;t work. In that case the
browser will request the same assets over and over again even thought they
didn&#8216;t change. You can use something like Live HTTP Headers for
Firefox to verify that the cache is indeed working.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000495">auto_discovery_link_tag</a>&nbsp;&nbsp;
      <a href="#M000508">cache_asset_timestamps</a>&nbsp;&nbsp;
      <a href="#M000509">cache_asset_timestamps=</a>&nbsp;&nbsp;
      <a href="#M000505">image_path</a>&nbsp;&nbsp;
      <a href="#M000507">image_tag</a>&nbsp;&nbsp;
      <a href="#M000498">javascript_include_tag</a>&nbsp;&nbsp;
      <a href="#M000496">javascript_path</a>&nbsp;&nbsp;
      <a href="#M000506">path_to_image</a>&nbsp;&nbsp;
      <a href="#M000497">path_to_javascript</a>&nbsp;&nbsp;
      <a href="#M000503">path_to_stylesheet</a>&nbsp;&nbsp;
      <a href="#M000499">register_javascript_expansion</a>&nbsp;&nbsp;
      <a href="#M000501">register_javascript_include_default</a>&nbsp;&nbsp;
      <a href="#M000500">register_stylesheet_expansion</a>&nbsp;&nbsp;
      <a href="#M000504">stylesheet_link_tag</a>&nbsp;&nbsp;
      <a href="#M000502">stylesheet_path</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">ASSETS_DIR</td>
          <td>=</td>
          <td class="context-item-value">defined?(Rails.public_path) ? Rails.public_path : &quot;public&quot;</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">JAVASCRIPTS_DIR</td>
          <td>=</td>
          <td class="context-item-value">&quot;#{ASSETS_DIR}/javascripts&quot;</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">STYLESHEETS_DIR</td>
          <td>=</td>
          <td class="context-item-value">&quot;#{ASSETS_DIR}/stylesheets&quot;</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">JAVASCRIPT_DEFAULT_SOURCES</td>
          <td>=</td>
          <td class="context-item-value">['prototype', 'effects', 'dragdrop', 'controls'].freeze unless const_defined?(:JAVASCRIPT_DEFAULT_SOURCES)</td>
        </tr>
        </table>
      </div>
    </div>



      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000508" class="method-detail">
        <a name="M000508"></a>

        <div class="method-heading">
          <a href="AssetTagHelper.src/M000508.html" target="Code" class="method-signature"
            onclick="popupCode('AssetTagHelper.src/M000508.html');return false;">
          <span class="method-name">cache_asset_timestamps</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
        </div>
      </div>

      <div id="method-M000509" class="method-detail">
        <a name="M000509"></a>

        <div class="method-heading">
          <a href="AssetTagHelper.src/M000509.html" target="Code" class="method-signature"
            onclick="popupCode('AssetTagHelper.src/M000509.html');return false;">
          <span class="method-name">cache_asset_timestamps=</span><span class="method-args">(value)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
You can enable or disable the asset tag timestamps cache. With the cache
enabled, the asset tag helper methods will make fewer expense file system
calls. However this prevents you from modifying any asset files while the
server is running.
</p>
<pre>
  ActionView::Helpers::AssetTagHelper.cache_asset_timestamps = false
</pre>
        </div>
      </div>

      <div id="method-M000499" class="method-detail">
        <a name="M000499"></a>

        <div class="method-heading">
          <a href="AssetTagHelper.src/M000499.html" target="Code" class="method-signature"
            onclick="popupCode('AssetTagHelper.src/M000499.html');return false;">
          <span class="method-name">register_javascript_expansion</span><span class="method-args">(expansions)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Register one or more javascript files to be included when <tt>symbol</tt>
is passed to <tt><a
href="AssetTagHelper.html#M000498">javascript_include_tag</a></tt>. This
method is typically intended to be called from plugin initialization to
register javascript files that the plugin installed in
<tt>public/javascripts</tt>.
</p>
<pre>
  ActionView::Helpers::AssetTagHelper.register_javascript_expansion :monkey =&gt; [&quot;head&quot;, &quot;body&quot;, &quot;tail&quot;]

  javascript_include_tag :monkey # =&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/head.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/body.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/tail.js&quot;&gt;&lt;/script&gt;
</pre>
        </div>
      </div>

      <div id="method-M000501" class="method-detail">
        <a name="M000501"></a>

        <div class="method-heading">
          <a href="AssetTagHelper.src/M000501.html" target="Code" class="method-signature"
            onclick="popupCode('AssetTagHelper.src/M000501.html');return false;">
          <span class="method-name">register_javascript_include_default</span><span class="method-args">(*sources)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Register one or more additional JavaScript files to be included when <tt><a
href="AssetTagHelper.html#M000498">javascript_include_tag</a>
:defaults</tt> is called. This method is typically intended to be called
from plugin initialization to register additional .js files that the plugin
installed in <tt>public/javascripts</tt>.
</p>
        </div>
      </div>

      <div id="method-M000500" class="method-detail">
        <a name="M000500"></a>

        <div class="method-heading">
          <a href="AssetTagHelper.src/M000500.html" target="Code" class="method-signature"
            onclick="popupCode('AssetTagHelper.src/M000500.html');return false;">
          <span class="method-name">register_stylesheet_expansion</span><span class="method-args">(expansions)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Register one or more stylesheet files to be included when <tt>symbol</tt>
is passed to <tt><a
href="AssetTagHelper.html#M000504">stylesheet_link_tag</a></tt>. This
method is typically intended to be called from plugin initialization to
register stylesheet files that the plugin installed in
<tt>public/stylesheets</tt>.
</p>
<pre>
  ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion :monkey =&gt; [&quot;head&quot;, &quot;body&quot;, &quot;tail&quot;]

  stylesheet_link_tag :monkey # =&gt;
    &lt;link href=&quot;/stylesheets/head.css&quot;  media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
    &lt;link href=&quot;/stylesheets/body.css&quot;  media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
    &lt;link href=&quot;/stylesheets/tail.css&quot;  media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
</pre>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000495" class="method-detail">
        <a name="M000495"></a>

        <div class="method-heading">
          <a href="AssetTagHelper.src/M000495.html" target="Code" class="method-signature"
            onclick="popupCode('AssetTagHelper.src/M000495.html');return false;">
          <span class="method-name">auto_discovery_link_tag</span><span class="method-args">(type = :rss, url_options = {}, tag_options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a link tag that browsers and news readers can use to auto-detect an
RSS or ATOM feed. The <tt>type</tt> can either be <tt>:rss</tt> (default)
or <tt>:atom</tt>. Control the link options in url_for format using the
<tt>url_options</tt>. You can modify the LINK tag itself in
<tt>tag_options</tt>.
</p>
<h4>Options</h4>
<ul>
<li><tt>:rel</tt> - Specify the relation of this link, defaults to
&quot;alternate&quot;

</li>
<li><tt>:type</tt> - Override the auto-generated mime type

</li>
<li><tt>:title</tt> - Specify the title of the link, defaults to the
<tt>type</tt>

</li>
</ul>
<h4>Examples</h4>
<pre>
 auto_discovery_link_tag # =&gt;
    &lt;link rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot; title=&quot;RSS&quot; href=&quot;http://www.currenthost.com/controller/action&quot; /&gt;
 auto_discovery_link_tag(:atom) # =&gt;
    &lt;link rel=&quot;alternate&quot; type=&quot;application/atom+xml&quot; title=&quot;ATOM&quot; href=&quot;http://www.currenthost.com/controller/action&quot; /&gt;
 auto_discovery_link_tag(:rss, {:action =&gt; &quot;feed&quot;}) # =&gt;
    &lt;link rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot; title=&quot;RSS&quot; href=&quot;http://www.currenthost.com/controller/feed&quot; /&gt;
 auto_discovery_link_tag(:rss, {:action =&gt; &quot;feed&quot;}, {:title =&gt; &quot;My RSS&quot;}) # =&gt;
    &lt;link rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot; title=&quot;My RSS&quot; href=&quot;http://www.currenthost.com/controller/feed&quot; /&gt;
 auto_discovery_link_tag(:rss, {:controller =&gt; &quot;news&quot;, :action =&gt; &quot;feed&quot;}) # =&gt;
    &lt;link rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot; title=&quot;RSS&quot; href=&quot;http://www.currenthost.com/news/feed&quot; /&gt;
 auto_discovery_link_tag(:rss, &quot;http://www.example.com/feed.rss&quot;, {:title =&gt; &quot;Example RSS&quot;}) # =&gt;
    &lt;link rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot; title=&quot;Example RSS&quot; href=&quot;http://www.example.com/feed&quot; /&gt;
</pre>
        </div>
      </div>

      <div id="method-M000505" class="method-detail">
        <a name="M000505"></a>

        <div class="method-heading">
          <a href="AssetTagHelper.src/M000505.html" target="Code" class="method-signature"
            onclick="popupCode('AssetTagHelper.src/M000505.html');return false;">
          <span class="method-name">image_path</span><span class="method-args">(source)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Computes the path to an image asset in the public images directory. Full
paths from the document root will be passed through. Used internally by
<tt><a href="AssetTagHelper.html#M000507">image_tag</a></tt> to build the
image path.
</p>
<h4>Examples</h4>
<pre>
  image_path(&quot;edit&quot;)                                         # =&gt; /images/edit
  image_path(&quot;edit.png&quot;)                                     # =&gt; /images/edit.png
  image_path(&quot;icons/edit.png&quot;)                               # =&gt; /images/icons/edit.png
  image_path(&quot;/icons/edit.png&quot;)                              # =&gt; /icons/edit.png
  image_path(&quot;http://www.railsapplication.com/img/edit.png&quot;) # =&gt; http://www.railsapplication.com/img/edit.png
</pre>
        </div>
      </div>

      <div id="method-M000507" class="method-detail">
        <a name="M000507"></a>

        <div class="method-heading">
          <a href="AssetTagHelper.src/M000507.html" target="Code" class="method-signature"
            onclick="popupCode('AssetTagHelper.src/M000507.html');return false;">
          <span class="method-name">image_tag</span><span class="method-args">(source, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an html image tag for the <tt>source</tt>. The <tt>source</tt> can
be a full path or a file that exists in your public images directory.
</p>
<h4>Options</h4>
<p>
You can add HTML attributes using the <tt>options</tt>. The
<tt>options</tt> supports three additional keys for convenience and
conformance:
</p>
<ul>
<li><tt>:alt</tt> - If no alt text is given, the file name part of the
<tt>source</tt> is used (capitalized and without the extension)

</li>
<li><tt>:size</tt> - Supplied as &quot;{Width}x{Height}&quot;, so
&quot;30x45&quot; becomes width=&quot;30&quot; and height=&quot;45&quot;.
<tt>:size</tt> will be ignored if the value is not in the correct format.

</li>
<li><tt>:mouseover</tt> - Set an alternate image to be used when the
onmouseover event is fired, and sets the original image to be replaced
onmouseout. This can be used to implement an easy image toggle that fires
on onmouseover.

</li>
</ul>
<h4>Examples</h4>
<pre>
 image_tag(&quot;icon&quot;)  # =&gt;
   &lt;img src=&quot;/images/icon&quot; alt=&quot;Icon&quot; /&gt;
 image_tag(&quot;icon.png&quot;)  # =&gt;
   &lt;img src=&quot;/images/icon.png&quot; alt=&quot;Icon&quot; /&gt;
 image_tag(&quot;icon.png&quot;, :size =&gt; &quot;16x10&quot;, :alt =&gt; &quot;Edit Entry&quot;)  # =&gt;
   &lt;img src=&quot;/images/icon.png&quot; width=&quot;16&quot; height=&quot;10&quot; alt=&quot;Edit Entry&quot; /&gt;
 image_tag(&quot;/icons/icon.gif&quot;, :size =&gt; &quot;16x16&quot;)  # =&gt;
   &lt;img src=&quot;/icons/icon.gif&quot; width=&quot;16&quot; height=&quot;16&quot; alt=&quot;Icon&quot; /&gt;
 image_tag(&quot;/icons/icon.gif&quot;, :height =&gt; '32', :width =&gt; '32') # =&gt;
   &lt;img alt=&quot;Icon&quot; height=&quot;32&quot; src=&quot;/icons/icon.gif&quot; width=&quot;32&quot; /&gt;
 image_tag(&quot;/icons/icon.gif&quot;, :class =&gt; &quot;menu_icon&quot;) # =&gt;
   &lt;img alt=&quot;Icon&quot; class=&quot;menu_icon&quot; src=&quot;/icons/icon.gif&quot; /&gt;
 image_tag(&quot;mouse.png&quot;, :mouseover =&gt; &quot;/images/mouse_over.png&quot;) # =&gt;
   &lt;img src=&quot;/images/mouse.png&quot; onmouseover=&quot;this.src='/images/mouse_over.png'&quot; onmouseout=&quot;this.src='/images/mouse.png'&quot; alt=&quot;Mouse&quot; /&gt;
 image_tag(&quot;mouse.png&quot;, :mouseover =&gt; image_path(&quot;mouse_over.png&quot;)) # =&gt;
   &lt;img src=&quot;/images/mouse.png&quot; onmouseover=&quot;this.src='/images/mouse_over.png'&quot; onmouseout=&quot;this.src='/images/mouse.png'&quot; alt=&quot;Mouse&quot; /&gt;
</pre>
        </div>
      </div>

      <div id="method-M000498" class="method-detail">
        <a name="M000498"></a>

        <div class="method-heading">
          <a href="AssetTagHelper.src/M000498.html" target="Code" class="method-signature"
            onclick="popupCode('AssetTagHelper.src/M000498.html');return false;">
          <span class="method-name">javascript_include_tag</span><span class="method-args">(*sources)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an html script tag for each of the <tt>sources</tt> provided. You
can pass in the filename (.js extension is optional) of javascript files
that exist in your public/javascripts directory for inclusion into the
current page or you can pass the full path relative to your document root.
To include the Prototype and Scriptaculous javascript libraries in your
application, pass <tt>:defaults</tt> as the source. When using
<tt>:defaults</tt>, if an application.js file exists in your public
javascripts directory, it will be included as well. You can modify the html
attributes of the script tag by passing a hash as the last argument.
</p>
<h4>Examples</h4>
<pre>
  javascript_include_tag &quot;xmlhr&quot; # =&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/xmlhr.js&quot;&gt;&lt;/script&gt;

  javascript_include_tag &quot;xmlhr.js&quot; # =&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/xmlhr.js&quot;&gt;&lt;/script&gt;

  javascript_include_tag &quot;common.javascript&quot;, &quot;/elsewhere/cools&quot; # =&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/common.javascript&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/elsewhere/cools.js&quot;&gt;&lt;/script&gt;

  javascript_include_tag &quot;http://www.railsapplication.com/xmlhr&quot; # =&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;http://www.railsapplication.com/xmlhr.js&quot;&gt;&lt;/script&gt;

  javascript_include_tag &quot;http://www.railsapplication.com/xmlhr.js&quot; # =&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;http://www.railsapplication.com/xmlhr.js&quot;&gt;&lt;/script&gt;

  javascript_include_tag :defaults # =&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/prototype.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/effects.js&quot;&gt;&lt;/script&gt;
    ...
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/application.js&quot;&gt;&lt;/script&gt;
</pre>
<ul>
<li>= The application.js file is only referenced if it exists

</li>
</ul>
<p>
Though it&#8216;s not really recommended practice, if you need to extend
the default JavaScript set for any reason (e.g., you&#8216;re going to be
using a certain .js file in every action), then take a look at the <a
href="AssetTagHelper.html#M000501">register_javascript_include_default</a>
method.
</p>
<p>
You can also include all javascripts in the javascripts directory using
<tt>:all</tt> as the source:
</p>
<pre>
  javascript_include_tag :all # =&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/prototype.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/effects.js&quot;&gt;&lt;/script&gt;
    ...
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/application.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/shop.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/checkout.js&quot;&gt;&lt;/script&gt;
</pre>
<p>
Note that the default javascript files will be included first. So Prototype
and Scriptaculous are available to all subsequently included files.
</p>
<p>
If you want Rails to search in all the subdirectories under javascripts,
you should explicitly set <tt>:recursive</tt>:
</p>
<pre>
  javascript_include_tag :all, :recursive =&gt; true
</pre>
<h2>Caching multiple javascripts into one</h2>
<p>
You can also cache multiple javascripts into one file, which requires less
HTTP connections to download and can better be compressed by gzip (leading
to faster transfers). Caching will only happen if
ActionController::Base.perform_caching is set to <tt>true</tt> (which is
the case by default for the Rails production environment, but not for the
development environment).
</p>
<h4>Examples</h4>
<pre>
  javascript_include_tag :all, :cache =&gt; true # when ActionController::Base.perform_caching is false =&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/prototype.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/effects.js&quot;&gt;&lt;/script&gt;
    ...
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/application.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/shop.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/checkout.js&quot;&gt;&lt;/script&gt;

  javascript_include_tag :all, :cache =&gt; true # when ActionController::Base.perform_caching is true =&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/all.js&quot;&gt;&lt;/script&gt;

  javascript_include_tag &quot;prototype&quot;, &quot;cart&quot;, &quot;checkout&quot;, :cache =&gt; &quot;shop&quot; # when ActionController::Base.perform_caching is false =&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/prototype.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/cart.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/checkout.js&quot;&gt;&lt;/script&gt;

  javascript_include_tag &quot;prototype&quot;, &quot;cart&quot;, &quot;checkout&quot;, :cache =&gt; &quot;shop&quot; # when ActionController::Base.perform_caching is true =&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;/javascripts/shop.js&quot;&gt;&lt;/script&gt;
</pre>
<p>
The <tt>:recursive</tt> option is also available for caching:
</p>
<pre>
  javascript_include_tag :all, :cache =&gt; true, :recursive =&gt; true
</pre>
        </div>
      </div>

      <div id="method-M000496" class="method-detail">
        <a name="M000496"></a>

        <div class="method-heading">
          <a href="AssetTagHelper.src/M000496.html" target="Code" class="method-signature"
            onclick="popupCode('AssetTagHelper.src/M000496.html');return false;">
          <span class="method-name">javascript_path</span><span class="method-args">(source)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Computes the path to a javascript asset in the public javascripts
directory. If the <tt>source</tt> filename has no extension, .js will be
appended. Full paths from the document root will be passed through. Used
internally by <a
href="AssetTagHelper.html#M000498">javascript_include_tag</a> to build the
script path.
</p>
<h4>Examples</h4>
<pre>
  javascript_path &quot;xmlhr&quot; # =&gt; /javascripts/xmlhr.js
  javascript_path &quot;dir/xmlhr.js&quot; # =&gt; /javascripts/dir/xmlhr.js
  javascript_path &quot;/dir/xmlhr&quot; # =&gt; /dir/xmlhr.js
  javascript_path &quot;http://www.railsapplication.com/js/xmlhr&quot; # =&gt; http://www.railsapplication.com/js/xmlhr.js
  javascript_path &quot;http://www.railsapplication.com/js/xmlhr.js&quot; # =&gt; http://www.railsapplication.com/js/xmlhr.js
</pre>
        </div>
      </div>

      <div id="method-M000506" class="method-detail">
        <a name="M000506"></a>

        <div class="method-heading">
          <span class="method-name">path_to_image</span><span class="method-args">(source)</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="AssetTagHelper.html#M000505">image_path</a>
</p>
        </div>
      </div>

      <div id="method-M000497" class="method-detail">
        <a name="M000497"></a>

        <div class="method-heading">
          <span class="method-name">path_to_javascript</span><span class="method-args">(source)</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="AssetTagHelper.html#M000496">javascript_path</a>
</p>
        </div>
      </div>

      <div id="method-M000503" class="method-detail">
        <a name="M000503"></a>

        <div class="method-heading">
          <span class="method-name">path_to_stylesheet</span><span class="method-args">(source)</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="AssetTagHelper.html#M000502">stylesheet_path</a>
</p>
        </div>
      </div>

      <div id="method-M000504" class="method-detail">
        <a name="M000504"></a>

        <div class="method-heading">
          <a href="AssetTagHelper.src/M000504.html" target="Code" class="method-signature"
            onclick="popupCode('AssetTagHelper.src/M000504.html');return false;">
          <span class="method-name">stylesheet_link_tag</span><span class="method-args">(*sources)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a stylesheet link tag for the sources specified as arguments. If
you don&#8216;t specify an extension, <tt>.css</tt> will be appended
automatically. You can modify the link attributes by passing a hash as the
last argument.
</p>
<h4>Examples</h4>
<pre>
  stylesheet_link_tag &quot;style&quot; # =&gt;
    &lt;link href=&quot;/stylesheets/style.css&quot; media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;

  stylesheet_link_tag &quot;style.css&quot; # =&gt;
    &lt;link href=&quot;/stylesheets/style.css&quot; media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;

  stylesheet_link_tag &quot;http://www.railsapplication.com/style.css&quot; # =&gt;
    &lt;link href=&quot;http://www.railsapplication.com/style.css&quot; media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;

  stylesheet_link_tag &quot;style&quot;, :media =&gt; &quot;all&quot; # =&gt;
    &lt;link href=&quot;/stylesheets/style.css&quot; media=&quot;all&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;

  stylesheet_link_tag &quot;style&quot;, :media =&gt; &quot;print&quot; # =&gt;
    &lt;link href=&quot;/stylesheets/style.css&quot; media=&quot;print&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;

  stylesheet_link_tag &quot;random.styles&quot;, &quot;/css/stylish&quot; # =&gt;
    &lt;link href=&quot;/stylesheets/random.styles&quot; media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
    &lt;link href=&quot;/css/stylish.css&quot; media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
</pre>
<p>
You can also include all styles in the stylesheets directory using
<tt>:all</tt> as the source:
</p>
<pre>
  stylesheet_link_tag :all # =&gt;
    &lt;link href=&quot;/stylesheets/style1.css&quot;  media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
    &lt;link href=&quot;/stylesheets/styleB.css&quot;  media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
    &lt;link href=&quot;/stylesheets/styleX2.css&quot; media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
</pre>
<p>
If you want Rails to search in all the subdirectories under stylesheets,
you should explicitly set <tt>:recursive</tt>:
</p>
<pre>
  stylesheet_link_tag :all, :recursive =&gt; true
</pre>
<h2>Caching multiple stylesheets into one</h2>
<p>
You can also cache multiple stylesheets into one file, which requires less
HTTP connections and can better be compressed by gzip (leading to faster
transfers). Caching will only happen if
ActionController::Base.perform_caching is set to true (which is the case by
default for the Rails production environment, but not for the development
environment). Examples:
</p>
<h4>Examples</h4>
<pre>
  stylesheet_link_tag :all, :cache =&gt; true # when ActionController::Base.perform_caching is false =&gt;
    &lt;link href=&quot;/stylesheets/style1.css&quot;  media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
    &lt;link href=&quot;/stylesheets/styleB.css&quot;  media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
    &lt;link href=&quot;/stylesheets/styleX2.css&quot; media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;

  stylesheet_link_tag :all, :cache =&gt; true # when ActionController::Base.perform_caching is true =&gt;
    &lt;link href=&quot;/stylesheets/all.css&quot;  media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;

  stylesheet_link_tag &quot;shop&quot;, &quot;cart&quot;, &quot;checkout&quot;, :cache =&gt; &quot;payment&quot; # when ActionController::Base.perform_caching is false =&gt;
    &lt;link href=&quot;/stylesheets/shop.css&quot;  media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
    &lt;link href=&quot;/stylesheets/cart.css&quot;  media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
    &lt;link href=&quot;/stylesheets/checkout.css&quot; media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;

  stylesheet_link_tag &quot;shop&quot;, &quot;cart&quot;, &quot;checkout&quot;, :cache =&gt; &quot;payment&quot; # when ActionController::Base.perform_caching is true =&gt;
    &lt;link href=&quot;/stylesheets/payment.css&quot;  media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
</pre>
<p>
The <tt>:recursive</tt> option is also available for caching:
</p>
<pre>
  stylesheet_link_tag :all, :cache =&gt; true, :recursive =&gt; true
</pre>
<p>
To force concatenation (even in development mode) set <tt>:concat</tt> to
true. This is useful if you have too many stylesheets for IE to load.
</p>
<pre>
  stylesheet_link_tag :all, :concat =&gt; true
</pre>
        </div>
      </div>

      <div id="method-M000502" class="method-detail">
        <a name="M000502"></a>

        <div class="method-heading">
          <a href="AssetTagHelper.src/M000502.html" target="Code" class="method-signature"
            onclick="popupCode('AssetTagHelper.src/M000502.html');return false;">
          <span class="method-name">stylesheet_path</span><span class="method-args">(source)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Computes the path to a stylesheet asset in the public stylesheets
directory. If the <tt>source</tt> filename has no extension, <tt>.css</tt>
will be appended. Full paths from the document root will be passed through.
Used internally by <tt><a
href="AssetTagHelper.html#M000504">stylesheet_link_tag</a></tt> to build
the stylesheet path.
</p>
<h4>Examples</h4>
<pre>
  stylesheet_path &quot;style&quot; # =&gt; /stylesheets/style.css
  stylesheet_path &quot;dir/style.css&quot; # =&gt; /stylesheets/dir/style.css
  stylesheet_path &quot;/dir/style.css&quot; # =&gt; /dir/style.css
  stylesheet_path &quot;http://www.railsapplication.com/css/style&quot; # =&gt; http://www.railsapplication.com/css/style.css
  stylesheet_path &quot;http://www.railsapplication.com/css/style.js&quot; # =&gt; http://www.railsapplication.com/css/style.css
</pre>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>