Rails assets working in development and not production

荒凉一梦 提交于 2019-12-24 03:25:00

问题


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

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