Rails 4 - Using CDN in Production

你离开我真会死。 提交于 2019-12-12 06:14:24

问题


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

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.


回答1:


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

rake assets:precompile RAILS_ENV=production


来源:https://stackoverflow.com/questions/30239842/rails-4-using-cdn-in-production

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