Flowdock
stylesheet_link_tag(*sources) public

Returns a stylesheet link tag for the sources specified as arguments. If you don’t specify an extension, .css will be appended automatically. You can modify the link attributes by passing a hash as the last argument.

Examples

  stylesheet_link_tag "style" # =>
    <link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />

  stylesheet_link_tag "style.css" # =>
    <link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />

  stylesheet_link_tag "http://www.railsapplication.com/style.css" # =>
    <link href="http://www.railsapplication.com/style.css" media="screen" rel="stylesheet" type="text/css" />

  stylesheet_link_tag "style", :media => "all" # =>
    <link href="/stylesheets/style.css" media="all" rel="stylesheet" type="text/css" />

  stylesheet_link_tag "style", :media => "print" # =>
    <link href="/stylesheets/style.css" media="print" rel="stylesheet" type="text/css" />

  stylesheet_link_tag "random.styles", "/css/stylish" # =>
    <link href="/stylesheets/random.styles" media="screen" rel="stylesheet" type="text/css" />
    <link href="/css/stylish.css" media="screen" rel="stylesheet" type="text/css" />

You can also include all styles in the stylesheet directory using :all as the source:

  stylesheet_link_tag :all # =>
    <link href="/stylesheets/style1.css"  media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/styleB.css"  media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/styleX2.css" media="screen" rel="stylesheet" type="text/css" />

Caching multiple stylesheets into one

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:

Examples

  stylesheet_link_tag :all, :cache => true # when ActionController::Base.perform_caching is false =>
    <link href="/stylesheets/style1.css"  media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/styleB.css"  media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/styleX2.css" media="screen" rel="stylesheet" type="text/css" />

  stylesheet_link_tag :all, :cache => true # when ActionController::Base.perform_caching is true =>
    <link href="/stylesheets/all.css"  media="screen" rel="stylesheet" type="text/css" />

  stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when ActionController::Base.perform_caching is false =>
    <link href="/stylesheets/shop.css"  media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/cart.css"  media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/checkout.css" media="screen" rel="stylesheet" type="text/css" />

  stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when ActionController::Base.perform_caching is true =>
    <link href="/stylesheets/payment.css"  media="screen" rel="stylesheet" type="text/css" />
Show source
Register or log in to add new notes.
April 6, 2009
3 thanks

Assets hosts

You can also setup assets hosts in enviroments:

config.action_controller.asset_host = "http://your-assets-server.com"