Search code examples
cssruby-on-rails-4cdnproduction-environment

Rails 4 - Using CDN in Production


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.


Solution

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

    rake assets:precompile RAILS_ENV=production