zpesk
zpesk

Reputation: 4353

Where do you put CSS files in a rails app directory?

Where should i create a folder to house my CSS files within my rails app directory??

Upvotes: 21

Views: 21205

Answers (6)

Katta Naveen Kumar
Katta Naveen Kumar

Reputation: 59

For Rails 4:

1) Add your .css file in app/assets/stylesheets

2) In your view file <%= stylesheet_link_tag 'uploaded_file_name' %>

Upvotes: 4

Anthony Panozzo
Anthony Panozzo

Reputation: 3474

For Rails 3.1+ apps, you should use the asset pipeline. Place stylesheets in app/assets/stylesheets/ if they are specific to your application. You can also put them at vendor/assets/stylesheets/ if they are external (say if they are stylesheets for a javascript plugin.)

After that, you will include stylesheets using the app/assets/stylesheets/application.css if it is included in your layout file (see other answers for how to do this.)

Upvotes: 20

Matt Briggs
Matt Briggs

Reputation: 42178

/app is for programmatic content (your models, views, controllers, layouts, partials, etc). /public is for your static content (html, images, stylesheets, javascripts, etc)

so the correct place for your stylesheets would be /public/stylesheets. If you follow this convention, you can use the stylesheet_link_tag helper, so if you put style.css into /public/stylesheets, then

<%= stylesheet_link_tag "style" %>

will get rendered as

<link href="/stylesheets/style.css?1232285206" media="screen" rel="stylesheet" type="text/css" />

Upvotes: 9

Ben Hughes
Ben Hughes

Reputation: 14185

for Rails 2.x : public/stylesheets

Upvotes: 18

James Conroy-Finn
James Conroy-Finn

Reputation: 343

stylesheet_link_tag takes arrays of stylesheets as well as a string.

For example:

= stylesheet_link_tag %w[ screen print ]

There are some great examples of using the stylesheet_link_tag helper at APIDock.

Upvotes: 0

Jason Miesionczek
Jason Miesionczek

Reputation: 14448

put it in public/stylesheets

then use

<%= stylesheet_link_tag "style_sheet_file_name" %>

in your

Upvotes: 3

Related Questions