Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Tutorial 3, stylesheet_link_tag generating incorrect link

I've set up application.html.erb to link to a stylesheet using the following code

<%= stylesheet_link_tag 'stylesheets/style', :media => 'screen' %>

However when I load the localhost in the browser window it prints this code

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

when I view the file directly I'm shown this error

Routing Error

No route matches [GET] "/assets/stylesheets/style.css"

I've read on some other questions that rails by default looks in public/stylesheets so I'm not sure why it's looking in assets?

I also tried to move the css file to the assets directory just to see if it would work however, it still doesn't work and gives the same routing error.

Been stuck on this for a couple of days and it's really doing my head in so appreciate any help you can give me.

Thanks in advance

like image 631
Chris Robinson Avatar asked Feb 21 '23 20:02

Chris Robinson


1 Answers

Rails 3 comes with a new assets management which is actually one of the biggest pluses.

A guide on how it works is here

So if you have the application.css file in your assets/stylesheets you can simply drop the style.css in your assets/stylesheets directory renaming it in style.css.scss

In your view just leave:

<%= stylesheet_link_tag    "application", media: 'screen' %>

Through sprockets the Rails app will load it.

like image 111
tommasop Avatar answered Feb 24 '23 10:02

tommasop