airplaneman19
airplaneman19

Reputation: 1159

Rails/Heroku precompiled assets not being found

I'm pretty new to Rails and Heroku, and I'm trying to deploy an app which uses the jQuery UI library. I have the jQuery UI Javascript and CSS files in my app/assets folder, and I have it set to precompile assets (I had to do that to get my app actually running on Heroku). However, the jQuery UI files are not being found when I load the page (jQuery UI is not working). From what I've gathered, it renames the files to <filename>-<md5 hash>.js/css. How can I make it reference the right file?

app/views/layouts/application.html.erb:

  <%= stylesheet_link_tag    "application" %>
  <%= javascript_include_tag "application" %>
  <%= javascript_include_tag "http://code.jquery.com/jquery-1.7.1.min.js" %>
  <%= javascript_include_tag "jquery-ui-1.8.16.custom.min" %>
  <%= stylesheet_link_tag "jquery-ui-1.8.16.custom" %>
  <%= stylesheet_link_tag "http://fonts.googleapis.com/css?family=Open+Sans:300italic,400,300" %>
  <%= csrf_meta_tags %>

Upvotes: 1

Views: 6713

Answers (3)

dobrinov
dobrinov

Reputation: 604

As described here (https://devcenter.heroku.com/articles/ruby-support#static-assets) you should add the 'rails_serve_static_assets' gem to your Gemfile, and the problem will be fixed.

Upvotes: 0

ylluminate
ylluminate

Reputation: 12369

I actually would recommend removing the precompiled assets function and allowing Heroku to do this for you. I initially started off like you did, however quickly found that it was a superior approach and recommended by Heroku support to do the asset compilation during slug compilation.

Be sure that you're using the Cedar stack rather than Bamboo and take a look at this and then follow below to the troubleshooting section: enter image description here

The side note is especially important: "If a public/assets/manifest.yml is detected in your app, Heroku will assume you are handling asset compilation yourself and will not attempt to compile your assets."

Be sure that you remove everything under your public/assets/* folder that the precompile has created, including that manifest.yml file.

Otherwise all of your JavaScript files in app/assets/javascripts should automatically be included and you should be able to see so while checking in your dev mode (in production mode on heroku by default they'll be all minified into one application.js file, but if they show up in dev mode, you should be gold).

Upvotes: 5

prusswan
prusswan

Reputation: 7091

If you are on the default Bamboo stack, you will need to precompile the assets by rake assets:precompile yourself and commit the results in public/assets and push them to Heroku. Otherwise, using the Cedar stack might be an easier choice.

Upvotes: 2

Related Questions