stylesheet_link_tag
stylesheet_link_tag(*sources)
public
Returns a stylesheet link tag for the sources specified as arguments.
When passing paths, the .css extension is optional. If you don’t specify an extension, .css will be appended automatically. If you do not want .css appended to the path, set extname: false in the options. You can modify the link attributes by passing a hash as the last argument.
If the server supports HTTP Early Hints, Rails will push a 103 Early Hints response that links to the assets.
Options
-
:extname - Append an extension to the generated URL unless the extension already exists. This only applies for relative URLs.
-
:protocol - Sets the protocol of the generated URL. This option only applies when a relative URL and host options are provided.
-
:host - When a relative URL is provided the host is added to the that path.
-
:skip_pipeline - This option is used to bypass the asset pipeline when it is set to true.
Examples
stylesheet_link_tag "style" # => <link href="/assets/style.css" rel="stylesheet" /> stylesheet_link_tag "style.css" # => <link href="/assets/style.css" rel="stylesheet" /> stylesheet_link_tag "http://www.example.com/style.css" # => <link href="http://www.example.com/style.css" rel="stylesheet" /> stylesheet_link_tag "style.less", extname: false, skip_pipeline: true, rel: "stylesheet/less" # => <link href="/stylesheets/style.less" rel="stylesheet/less"> stylesheet_link_tag "style", media: "all" # => <link href="/assets/style.css" media="all" rel="stylesheet" /> stylesheet_link_tag "style", media: "print" # => <link href="/assets/style.css" media="print" rel="stylesheet" /> stylesheet_link_tag "random.styles", "/css/stylish" # => <link href="/assets/random.styles" rel="stylesheet" /> # <link href="/css/stylish.css" rel="stylesheet" />
Assets hosts
You can also setup assets hosts in enviroments:
config.action_controller.asset_host = "http://your-assets-server.com"