How to specify Style-sheets path, full path, url in stylesheet_link_tag (rails helper) [for beginners]


You can specify a full path relative to the document root, or a URL.
Specify URL and how to specify it:
When you need this:
1. You want to use your html view to be displayed on some external site. OR
2. You want to use some external Style sheet in your project.
Wrong way:

<%= stylesheet_link_tag "#{request.host_with_port}/assets/get_tile" %> 

Correct way:

<%= stylesheet_link_tag "http://#{request.host_with_port}/assets/get_tile" %>

Note
If you are using css or scss it does not matter. Rails will automatically detect it.

Specify path

To include app/assets/stylesheets/get_tile.css.scss and
app/assets/stylesheets/subfolder/your_file.css  OR app/assets/stylesheets/subfolder/your_file.css.scss
<%= stylesheet_link_tag "get_tile", "subfolder/your_file" %>

For example, to link to a stylesheet file that is inside a directory called style-sheets inside of one of app/assets, lib/assets or vendor/assets, you would do this:

<%= stylesheet_link_tag "your_css_file_name" %>
Advertisements

I am Senior Software Engineer. I love reading, writing, sharing,developing, hiking, movies, trips, mountains, brooks, hills etc.

Tagged with: , ,
Posted in Css, scss

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

StackOverFlow
Categories
Archives
%d bloggers like this: