Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a Rails 3.2 project on Apache. In the views/layouts/application.html.erb file I have the lines

<%= stylesheet_link_tag :all %>
<%= yield :javascript_includes %>

Instead of including all the CSS and JavaScript files, it includes only all.css and defaults.js (which are non-existent). How can I make it link to all CSS and JavaScript files?

share|improve this question

1 Answer

up vote 1 down vote accepted

Since you're on Rails 3.2, Sprockets is being used to load your static assets from your manifest files. To include all the assets in your default stylesheets and javascripts folders, you can do the following:

# application.js
//= require jquery
//= require jquery_ujs
//= require_tree .

require_tree . tells Sprockets to load and compile all the Javascript (and CoffeeScript) files in your app/assets/javascripts directory.

# app/assets/stylesheets/application.css
*= require_self
*= require_tree . 

Similarly, require_tree . tells Sprockets to load all the CSS (and SCSS) files within the app/assets/stylesheets directory.

Then, if your layout, you'd include the following include tags in place of the tags you listed in your question:

# app/views/layouts/application.html.erb
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>

You may want to check out the official Rails guide to the asset pipline. The asset pipeline is a major update to Rails 3.1 – one which many users think is a big improvement – that has a material impact on the way static assets are loaded.

share|improve this answer
I see... Apparently the lines in application.js and application.css are already there, so I just modified the stylesheet_link_tag and javascript_include_tag to point to them. Cool! – Mika H. 2 days ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.