简体   繁体   English

Heroku Rails 4没有正确引用我的JavaScript资产位置

[英]Heroku Rails 4 not referencing my JavaScript assets location correctly

My local development runs fine, rendering javascript_include_tag "some-script" as referencing /assests/some-script.js correctly. 我的本地开发运行正常,将javascript_include_tag "some-script"呈现为正确引用/assests/some-script.js

In Heroku, it references /javascripts/some-script.js 在Heroku中,它引用/javascripts/some-script.js

I'm using gem 'rails_12factor' in production in my Gemfile 我使用gem 'rails_12factor'生产在我Gemfile

Do I need to change any asset configuration settings? 我需要更改任何资产配置设置吗? Like precompiling assets? 像预编译资产一样? I'm aware there are several config settings, but I'm unsure when to use them, in the past I've been fine without modifying them ( like this suggestion ). 我知道有几个配置设置,但是我不确定何时使用它们,过去我一直很好,无需修改它们( 像这样的建议 )。

It's just odd it references the /javascripts folder... 引用/javascripts文件夹很奇怪...

Also, to note, I am not currenty using javascript_include_tag "application" in layout/application.html.erb I am importing scripts manually using javascript_include_tag "some-script" in specific view erb files 另外,需要注意的是,我目前不是在layout/application.html.erb使用javascript_include_tag "application" ,而是在特定视图erb文件中使用javascript_include_tag "some-script"手动导入脚本

Secondly, /assets/some-script.js comes up as a 404, so this must means my assests aren't available, which could be a second issue. 其次,/ /assets/some-script.js作为404出现,因此这必须表示我的资产不可用,这可能是第二个问题。

Any ideas? 有任何想法吗?

This answer helped me resolve my issue. 这个答案帮助我解决了我的问题。 I had to manually add the js files to the assets precompile list in config/environments/production.rb like so: 我必须手动将js文件添加到config/environments/production.rb的资产预编译列表,如下所示:

config.assets.precompile += %w( some-script.js )
config.assets.precompile += %w( some-script2.js )
...

When I use a script in a view javascript_include_tag "some-script" works. 当我在视图javascript_include_tag "some-script"使用脚本时, javascript_include_tag "some-script"有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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