Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm working on a ROR app. It has a style.css stylesheet in its public/scaffold_files folder. I can see the style reference to this file when I inspect the elements. But now I want to change/add some styles. Any changes I make to this file is not affected in the view. How do we add new styles?? I dont want to use the <style> tag and write code in the view itself, I want it in a stylesheet. PS: this style.css file is referred in the layout file as below and I can see the same when I do 'view page source'.

  <link href="/scaffold_files/style.css" rel="stylesheet" type="text/css" media="all">
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
261 views
Welcome To Ask or Share your Answers For Others

1 Answer

The rails asset pipeline is broken up into 3 different sections.

  • app/assets is for assets that are owned by the application, usually scripted by yourself.

  • lib/assets is for your own libraries' code that doesn't really fit
    into the scope of the application or those libraries which are shared across applications.

  • vendor/assets is for assets that are 3rd party, such as js plugins and frameworks.

It is generally bad practise to start adding assets in the public folder. When your asset pipeline tries to compile and compress them in production, it won't be able to find them because it only looks in the app, lib and vendor folders.

To get started, just create a file called 'application.css' within the app/assets folder. Then reference this file within your layout (layout/application.html.erb) using the following syntax:

<%= stylesheet_link_tag :application %>

This will automatically look in the app/assets folder, and retrieve, the file named 'application'. Thereby rendering new styles within your applcation!

If you need further help with assets, check out the RailsGuides; they have alot of helpful and in depth content.

http://guides.rubyonrails.org/asset_pipeline.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...