Rails Tutorial 3, stylesheet_link_tag generates invalid link

I set application.html.erb to reference the stylesheet using the following code

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

However, when I load localhost in a 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 show this error

Routing error

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

I read some other questions that rails are looked at by default in public / stylesheets, so I'm not sure why it looks into assets?

I also tried moving the css file to the asset directory to make sure that it would work, but it still does not work and gives the same routing error.

Stuck on this for a couple of days and it really makes my head so appreciate any help you can give me.

Thank you in advance

+4
source share
1 answer

Rails 3 comes with new asset management, which in fact is one of the biggest pluses.

Guide to his work here

So, if you have an application.css file in your files / style sheets, you can just drop style.css in the / stylesheets resource directory by renaming it to style.css.scss

In your opinion, just leave:

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

Through the stars, the Rails application will download it.

+8
source

Source: https://habr.com/ru/post/1391206/


All Articles