Heroku can't find files in my Ruby on Rails app - even though they are right there?

强颜欢笑 提交于 2019-12-10 18:59:05

问题


When I try to access my site, then check my Heroku logs, I see this error:

ActionView::Template::Error (couldn't find file 'reset' 2012-06-13T02:31:43+00:00 app[web.1]: (in /app/app/assets/stylesheets/application.css:4)):

(application.css contains the line *= require reset)

Then I thought to run "heroku run bundle exec rake assets:precompile:all" but this gives a similar error:

-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       couldn't find file 'main/first.js.coffee'
       (in /tmp/build_3428u21sggsoc/app/assets/javascripts/application.js:1)
       Tasks: TOP => assets:precompile:primary

(That file is the first one required from my application.js, which has first line "//= require main/first.js.coffee")

In summary: my application runs fine locally, but when I deploy to Heroku, the files can no longer be found. Any ideas why?

Edit: here is the project tree. (There is one more directory before the app one, and that is the main project directory that also contains config, db, log, etc)

Another edit: there is no problem with .gitignore, or .slugignore.


回答1:


At first, I would suggest you to run your application in production mode on your local computer. There are some errors (in assets but I also found some in routing) which can have impact only for production environment so you can test and fix them locally instead of having to do it from the production server.

About the asset precompilation on Heroku, the solution given by akjoe should result in compiled assets tracked in git repo : with this option, you should disable the asset precompilation which happen on Heroku and let Rails serve you assets (set config.serve_static_assets = true in your production.rb file) but this is not the best way to deal with the asset pipeline as you lost one of his major benefice which is freeing your rails application of request for asset. To make it working properly, you should setup something like heroku explain : Using Rack::Cache with Memcached for Static Asset Caching in Rails 3.1+

I would also suggest you to try the assets precompilation locally in production environment RAILS_ENV=production bundle exec rake assets:precompile. To see if you got any error.

Finally you may want to check this different links to find useful information :

  • Rails 3.1+ Asset Pipeline on Heroku Cedar
  • Railscasts : #279 Understanding the Asset Pipeline
  • Rails Guide



回答2:


I've had almost exactly the same problem and similar errors with stylesheets edits not taking effect... I found that I would edit css (or as in your case references to css files) which seemed to be ignored by Heroku. Turns out Heroku was ONLY referencing the stylesheets in the public/assets directory. I cleared this directory and was able to get it working. I later found that you need to precompile your assets directory BEFORE you checkin to git. You would do this as follows:

  1. Precompile assets directory: rake assets:precompile
  2. Add the project files to the current Git repository: git add .
  3. Checkin the file changes to the current Git repository: git commit -am "description goes here"
  4. Push the files to Heroku: git push heroku master (substitute 'master' for the branch you wish to push to Heroku).

Hope that helps!



来源:https://stackoverflow.com/questions/11007524/heroku-cant-find-files-in-my-ruby-on-rails-app-even-though-they-are-right-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!