Rails资产正在开发而不是在生产中 [英] Rails assets working in development and not production

查看:74
本文介绍了Rails资产正在开发而不是在生产中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

年龄大了,我听不懂链轮"的问题;

the age old, "I don't understand sprockets" question;

我在app/assets/javascript/jquery.fancybox.js中有一项资产,我使用<%= javascript_include_tag('jquery.fancybox.js')%>来访问/加载它.

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...

更新文件后,我正在运行耙资产:预编译并重新启动服务apache2".

after updating the files, I'm running "rake assets:precompile and service apache2 restart".

推荐答案

在生产中,您只能引用已预编译的(javascript_include_tagstylesheet_link_tag)资产.默认情况下,这只是application.js和application.css.这些顶级文件(称为清单)包含指令,该指令说明要包含哪些文件(例如,默认情况下包括app/assets/javascripts/*).

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).

任何直接引用的内容都需要添加到config.assets.precompile

Anything that is to be referenced directly needs to be added to config.assets.precompile

sprockets_better_errors 宝石会在开发中警告您.

The sprockets_better_errors gem will warn you about these in development.

这篇关于Rails资产正在开发而不是在生产中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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