Rails 4-在生产中使用CDN [英] Rails 4 - Using CDN in Production

查看:85
本文介绍了Rails 4-在生产中使用CDN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Rails 4应用程序中,我正在使用资产管道来提供自定义的css / js文件。我还使用了两个CDN提供程序进行样式设置。一切都在开发中运作良好;但是,当我转到生产环境并尝试将应用程序部署到VPS时,我的应用程序似乎没有从CDN提供程序中获取css / js内容。这是我的app / views / layouts / application.html.haml的摘录(注意:我使用的是haml而不是erb)

In my Rails 4 application, I'm using asset pipeline to serve my custom css/js files. I'm also using a couple of cdn providers for styling as well. Everything works fine in development; however, when I switch to production and try to deploy my application to my VPS, my app doesn't seem to pick up the css/js content from the CDN providers. Here is an excerpt from my app/views/layouts/application.html.haml (Note: I'm using haml instead of erb)

!!!
%html
  %head
    %title Muse
    = stylesheet_link_tag    'application', media: 'all'
    = javascript_include_tag 'application'
    %link{:rel => "stylesheet", :href => "http://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.1/normalize.min.css"}
    %link{:rel => "stylesheet", :href => "http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css"}
    %link{:rel => "stylesheet", :href => 'http://fonts.googleapis.com/css?family=Roboto:400,300,700'}
    = csrf_meta_tags

我确定我错过了一大步。我四处搜寻,发现了许多复杂且矛盾的观点。我希望有人能帮助我,并阐明使Rails应用从生产中的CDN中获取样式内容的必要条件。

I'm sure I'm missing a huge step. I have searched around and found many complex and conflicting views. I hope someone can help me out and shed some light on what is necessary to make a rails app fetch the styling content from CDNs in production.

推荐答案

我想我找到了解决方案。真是愚蠢。只需在您的本地计算机上运行以下命令

I guess I found the solution. It's unbelievably silly. Just run the following on your local machine

rake assets:precompile RAILS_ENV=production

这篇关于Rails 4-在生产中使用CDN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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