Chris Robinson
Chris Robinson

Reputation: 111

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

Upvotes: 4

Views: 4024

Answers (1)

tommasop
tommasop

Reputation: 18765

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.

Upvotes: 8

Related Questions