0

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">
Aks..
  • 1,343
  • 1
  • 20
  • 42

1 Answers1

1

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

JellyFishBoy
  • 1,658
  • 1
  • 17
  • 25
  • Thanks JellyFishBoy.. I dint create a new style sheet but added this to my layout file <%= stylesheet_link_tag :style%>.. I copied my style.css from public to app/assets and referred it.. Now it works :) – Aks.. Nov 28 '13 at 11:45