AssetTagHelper
In Rails terms, an asset is something static that you want to include on a web page that isn’t controlled by Rails. These include things like stylesheets, JavaScript libraries, and sometimes images.
When working on a small scale, assets are stored in the public/ directory of your Rails application,
but you can put them on a separate server and tell Rails where to find
them through ActionController::Base.asset_host. A separate
server can speed delivery, let you share assets with other applications,
or just reduce the amount of work your Rails application has to do
itself.
The methods in AssetTagHelper
will assume files are in your public/ directory unless you’ve specified
otherwise. Most of them generate HTML tags for you, though a few let you
specify ways to generate tags in the future.
The methods you should probably focus on initially include:
auto_discovery_link_tagLets you specify the location of an RSS or Atom feed.
image_tagReturns an HTML
imgtag for the specified image name.javascript_include_tagReturns a
scripttag for the JavaScript files you identify as parameters. If one of the parameters is:defaults, the application.js file will be included, bringing in the Prototype and Script.aculo.us libraries. You can provide full paths to your scripts, even scripts on other servers, or you can just provide the file’s name. If you’re feeling fancy, you can define groups of styles withregister_javascript_expansion, and reference them with symbols.stylesheet_link_tag
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access