问题
the age old, "I don't understand sprockets" question;
I have an asset in app/assets/javascript/jquery.fancybox.js, I use <%=javascript_include_tag('jquery.fancybox.js')%> to access/load it.
this works in development, but not in production. I'm looking at the logs, but there must be something going on there, because I can't see the exact errors it's loading. Just the handlers in place (error only happens in 'production'). anways...
after updating the files, I'm running "rake assets:precompile and service apache2 restart".
回答1:
In production you can only reference (javascript_include_tag
, stylesheet_link_tag
) assets that have been precompiled. By default this is just application.js and application.css. These top level files (called manifests) contain directives saying what files to include (by default this include app/assets/javascripts/* for example).
Anything that is to be referenced directly needs to be added to config.assets.precompile
The sprockets_better_errors gem will warn you about these in development.
来源:https://stackoverflow.com/questions/23230799/rails-assets-working-in-development-and-not-production