Saturday, November 16, 2013

Can't get CSS working on Production or Heroku using Rails 4

I am using Rails 4. In development environment its working fine but in Production its not loaded.

Solution:
Run this command:

        RAILS_ENV=production bundle exec rake assets:precompile

Rails comes bundled with a rake task to compile the asset manifests and other files in the pipeline to the disk.

You can call this task on the server during deployment to create compiled versions of your assets directly on the server.

Rails introduced the Asset Pipeline to concatenate and minify or compress JavaScript and CSS assets. Heroku has a step in the build process to precompile your assets into your slug, so they’re readily available. To speed up asset precompiles, it’s recommended that you tell Rails to only partially load your app. Heroku also, does not provide the whole app environment to the build process, so this is required. In your config/application.rb set the following:

        config.assets.initialize_on_precompile = false
If  you have other manifests or individual stylesheets and JavaScript files to include, you can add them to the precompile array in config/application.rb:

         config.assets.precompile += ['zebra.js', 'zebra.css', 'table.js']

And if you want to clean assets then do it:

           rake assets:clean

This command removes compiled assets.
Reactions:

0 comments:

Post a Comment