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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With