Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

html - Adding new styles to stylesheet not working in rails

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

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...