Rails 预编译 - all.js 缺失
我是rails新手,使用版本3.1.0并尝试部署到heroku。我有一个非常简单的应用程序,在解决了几个问题后,我成功地在 heroku 上启动并运行了它。我使用命令
bundle exec rake assets:precompile
让heroku加载应用程序的资源(我读到heroku需要这个版本3.1.0)。问题是,当我尝试运行应用程序时,服务器给出错误,
ActionController::RoutingError (No route matches [GET] "/assets/all.js"):
我在 public/javscripts 中拥有所有必需的 javascript 文件,但我在资产目录中找不到 all.js 的任何版本。我已包含
config.assets.precompile << '*.js'
在 config/application.rb 中,但无济于事。
我想知道是否有人可以告诉我如何进行预编译以在资产目录中创建 all.js,或者我是否完全偏离了轨道。我的印象是预编译函数将所有 javascript 文件编译成一个优化文件。
另外,如果有人有任何好的链接供初学者了解预编译功能在 Rails 中的工作原理,我将非常感激。
提前致谢。
I am new to rails and using version 3.1.0 and trying to deploy to heroku. I have a very simple application that i have managed to get up and running on heroku after working my way through several issues. I used the command
bundle exec rake assets:precompile
to get heroku to load the assets for the application (i read that heroku requires this for version 3.1.0). The problem is that when i try to run the application, the server gives the error
ActionController::RoutingError (No route matches [GET] "/assets/all.js"):
i have all of the required javascript files in public/javscripts but i cannot find any version of all.js in the assets directory. I have included
config.assets.precompile << '*.js'
in config/application.rb but to no avail.
I was wondering if someone could tell me how I get the precompile to create all.js in the assets directory or if I am completely off track here. i was under the impression that the precompile function compiled all of the javascript files into a single optimized file.
Also, if anyone has any good links for a beginner to understand how the precompile functionality works in rails I would be very appreciative.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好的指南是官方 Rails 指南。还有关于它的 Railscast 。
简而言之,您的 Javascript 文件位于 app/assets/javascript 中,预编译任务将在其中处理它们,然后将其放入 public/assets 目录中。如果遵循默认值,则不必更改预编译配置选项。不要忘记使用正确的助手来引用您的文件。
阅读上面的资源,如果您要转换现有的应用程序,请观看 Railscast 并按照指南的最后一部分进行操作 - 这些应该会为您指明正确的方向。
The best guide is the official rails guide. There is also the Railscast about it.
In a nutshell your Javascript files go in app/assets/javascript from where the precompile task will process them and put then in the public/assets directory. You should not have to change the precompile config option if the follow the defaults. Don't forget to the use the correct helpers to reference your files.
Read the resources above, and if you are converting an existing app watch the Railscast and follow the last section of the guide - these should point you in the right direction.