Heroku Rails 4没有正确引用我的JavaScript资源位置 [英] Heroku Rails 4 not referencing my JavaScript assets location correctly

查看:118
本文介绍了Heroku Rails 4没有正确引用我的JavaScript资源位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的本​​地开发运行正常,将 javascript_include_tagsome-script引用为 /assests/some-script.js 正确。



在Heroku中,它引用了 /javascripts/some-script.js



我在 Gemfile中使用 gem'rails_12factor'生产



我是否需要更改任何资产配置设置?像预编译资产一样?我知道有几个配置设置,但我不确定何时使用它们,在过去,我一直没有修改它们( like this suggestion )。

它只是引用了 / javascripts 文件夹。 。
$ b

另外,要注意的是,我不是当前在中使用 javascript_include_tagapplication layout / application.html.erb 我正在使用 javascript_include_tagsome-script在特定视图erb文件中手动导入脚本



其次, /assets/some-script.js 成为404,所以这必定意味着我的资产不可用,可能是第二个问题。



任何想法?

解决方案

< a href =https://stackoverflow.com/questions/18469776/heroku-and-rails-4-some-javascript-not-working/18470309#18470309>这个答案帮我解决了我的问题。我必须手动将js文件添加到 config / environments / production.rb 中的资产预编译列表中:

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

当我在视图 javascript_include_tag中使用脚本时-script的作品。


My local development runs fine, rendering javascript_include_tag "some-script" as referencing /assests/some-script.js correctly.

In Heroku, it references /javascripts/some-script.js

I'm using gem 'rails_12factor' in production in my 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...

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

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.

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:

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.

这篇关于Heroku Rails 4没有正确引用我的JavaScript资源位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆