stylesheet_link_tag assets directory in Rails 4

Samuele Bistoletti picture Samuele Bistoletti · Aug 25, 2013 · Viewed 12.3k times · Source

I just started to develop in Ruby On Rails and I can not solve this problem: when I use the helper stylesheet_link_tag in the file / app / view / layouts / application.html.erb I can only reach the css file in / app / assets / stylesheets, but if I wanted to include some css files that are not found in that directory but in / app / assets / example, for example, how could I do (always using the helper stylesheet_link_tag)?

I tried to look at other pages of the forum on this topic but they were not helpful, I hope that by being more specific someone can help me ...

Answer

Samuele Bistoletti picture Samuele Bistoletti · Aug 31, 2013

I solved the problem: in the path to the file should be placed only the filename and not the entire route, rails will then search the css files in all subfolders of /assets. For example if I need a css file in /assets/css_dir/layout.css I should only write this code:

<%=  stylesheet_link_tag "layout" %> 

and nothing more. This solution worked for me.