Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

application.css asset pipeline

I'm on Rails 3.2.8 and I want to switch to using the asset pipeline.

I am on my dev machine, and have my assets set up like this: app/assets/stylesheets/application.css:

  ...    
  *= require_directory ../public/javascripts/jquery/themes/base
  *= require_directory ../public/prototype/stylesheets/css
*/

All my stylesheets and js and images are in the public folder which is a catch-all for now. The folder structure:

app/assets
  /stylesheets
    /application.css
  /javascripts
  /images
  /public
    /stylesheets
    /javascripts
    /prototype
    /images

Currently the public/assets/application.css file is empty. How do I compile this file in the development environment?

When I run Rails.application.config.assets.paths in rails console, I'm getting app/assets/public and not the full directory path for the assets.

In the views, I call the asset pipeline stylesheets: <%= stylesheet_link_tag 'application.css' %>

EDIT 1: I tried moving all the stylesheets to app/assets/stylesheets/ but it is not compiling the application.css properly in the view. It compiles to this:

<link href="/assets/application.css" media="screen" rel="stylesheet" type="text/css" />

And when I view the link, localhost:3000/assets/application.css it is a blank file.

EDIT 2: I used single quotes instead of double quotes and that fixed the syntax errors. I think I have a handle on it now that I've figured out the pathing. Thanks!

like image 586
John Avatar asked Dec 04 '12 18:12

John


1 Answers

Just leave the original settings of the application.css and let the asset pipeline do the job:

*= require_self
*= require_tree .

And in your layout you should be able to load the compiled application.css file:

<%= stylesheet_link_tag "application", :media => "all" %>

I disagree with Tam's answer. You shouldn't have to put your files anywhere other then the default locations in development. You can easily mess up your stuff, and unless you need requireJS-like assets management, you can benefit a lot from the asset pipeline.

Here is everything you need to know about the asset pipeline: http://guides.rubyonrails.org/asset_pipeline.html

like image 146
robertp Avatar answered Sep 30 '22 02:09

robertp