简体   繁体   中英

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 %>

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: 在此处输入图片说明

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).

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.

如此处所述( https://devcenter.heroku.com/articles/ruby-support#static-assets ),您应该将'rails_serve_static_assets'gem添加到您的Gemfile中,此问题将得到解决。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM