Localhost in rails does not show CSS

2

I already link the css with the html but even so the page does not show the css settings, only the html ... I am working with rails.

    
asked by Fabian Ortiz 07.03.2017 в 20:08
source

6 answers

0

You have incorrectly referenced the route to the asset, since you are using an absolute route. You have to enter the path relative to the file. For this, from the root route of the project, you enter the route in this way:

(imagining that the root of the project is hello_world )

<link href="app/assets/stylesheets/welcome.scss" rel="stylesheets" type="text/css">

Anyway, the file you want to include is not a pure CSS, but an SCSS (typical of the SASS framework).

I hope it will be useful for you. Successes!

    
answered by 07.03.2017 в 20:17
0

You probably can not find your file. So I can see your project is on the desktop, in the "boomerang" folder I recommend (if you still do not have it) that you believe in the boomeran folder, another folder which you can call css. Once created, inside it place your file "welcome.scss"

Now you only have to add the following:

<link rel="stylesheet" href="css/welcome.css" type="text/css">
    
answered by 07.03.2017 в 20:17
0

An SCSS file has to be compiled and you should not go directly to the HTML view. Only application.css.scss is precompiled by default. The rest of the files have to be included expressly. You could do it with an @import or with require_tree, or by modifying config / initializers / assets / and including your asset.

Suggestion of solution: 1) Inside app / assets / stylesheets create the file tuarchivo.scss 2) Put your styles there 3) In application.css.scss add the following code below:

@import 'tuarchivo';

4) In the console you have a rake assets: precompile 5) In your layout (view) you have the following reference (using the Rails helper)

<%= stylesheet_link_tag     'application', media: 'all', 'data-turbolinks-track' => true %>

NOTE: That last code example assumes that you are using Turbolink. It comes by default in a Rails application.

    
answered by 08.03.2017 в 20:44
0

Use the helper stylesheet_link_tag in your view as follows

<%= stylesheet_link_tag 'welcome.scss' %>
    
answered by 09.03.2017 в 08:43
0

Delete that line that you put to link, and replace it with the following:

<%= stylesheet_link_tag    'default', media: 'all', 'data-turbolinks-track': 'reload' %>

And change the extension of your scss file to

welcome.scss > welcome.css.scss

That should be enough.

    
answered by 22.05.2017 в 17:52
0

You have edited index.html.erb as if it were your main layout. All that code should go in application.html.erb (where the css and js are referenced) in the way it explains Sorry to you (which should already appear by default):

<%= stylesheet_link_tag     'application', media: 'all', 'data-turbolinks-track' => true %>

How does it work?

Rails packages all files css and js in the respective files application.js and application.css.scss at the time of compiling, this is because in application.css.scss you have the annotation =require_tree , which means that all the css files that you have will already be referenced in application.css.scss worth the redundancy; therefore:

  • Remove all the code from index and leave only the tags to show your content <div> , since index will be rendered in <%= yield %> , which is in application.html.erb "your true layout".
  • I recommend rails documentation to see how this works.

        
    answered by 25.05.2017 в 17:22