问题
in my app/assets/javascripts/specific.js
I have
//= require_tree ./specific
in app/assets/javascripts/specific/chat
I have pusher.js
Also, in config/environments/production
I have
config.assets.precompile += %w( specific.js some_other_manifest.js )
However, when I go into production (on heroku) it still complains pusher.js
is not precompiled. What am I doing wrong here?
While the application is deployed, the javascript files seem to be compiled.
from Heroku logs:
Compiled specific/chat/pusher.js (0ms) (pid 1042)
Compiled specific.js (60ms) (pid 1042)
But when I go to the view,
ActionView::Template::Error (specific/chat/pusher.js isn't precompiled):
1: <%= javascript_include_tag 'specific/chat/pusher' %>
2: <%= javascript_include_tag params[:controller] %>
3:
4: <div id="chat-header">
app/views/messages/index.html.erb:1:in `_app_views_messages_index_html_erb___3285714722884343394_70246542189040'
I also tried putting config.assets.precompile ..
option inside config/application.rb
instead of production.rb
Related: Assets say "not precompiled" when they are precompiled
When I run assets:precompile
and look in public/assets
folder, I see that they are all precompiled (e.g. specific-bfgbfbf4534535.js
)
So the asset is actually precompiled, but the error says it isn't precompiled
From my view:
<%= javascript_include_tag 'specific/chat/pusher.js' %>
回答1:
You don't include specific files, you include the entire manifest, that's the whole point of manifests.
This can't work:
<%= javascript_include_tag 'specific/chat/pusher' %>
Instead, you need a single include for the top-level manifest:
<%= javascript_include_tag 'specifics' %>
From your comment below your question:
It's not supposed to be included in application.html.erb
That isn't how precompiled assets work. You need to include specifics.js
, or build another (more granular) manifest. The point of manifests is that they produce a single minified blob of code to be included. You specifically say you see a specific-bfgbfbf4534535.js
in your compiled assets folder; that is the file that will be included, and it contains pusher.js
.
回答2:
try to precompile all assets:
config.assets.precompile += %w( *.css *.js )
来源:https://stackoverflow.com/questions/17055213/javascripts-not-precompiled