Heroku due to its nature(read-only file system) won’t allow us to write inside the public directory. This makes assert-packaging with jammit a complex one.
The read/write permission was only to the log or tmp directory.
In order to resolve this problem, the heroku-jammit plugin can be used.
Step-1:
Install the Jammit gem by,
$ sudo gem install jammit
Add the Gem to your config/environment.rb
config.gem "jammit"
If you use .gems file for installing gem in server, then add ‘jammit’ to your .gems file.
For Rails-2.3.*
Add the following line in your config/routes.rb
require 'jammit'
ActionController::Routing::Routes.draw do |map|
...
Jammit::Routes.draw(map)
...
end
For Rails-3 the route will be loaded automatically.
Jammit uses config/assets.yml configuration file.
embed_assets: on
javascripts:
workspace:
- public/javascripts/javascript_1.js
- public/javascripts/javascript_2.js
- public/javascripts/jquery/ui/minified/javascript_3.js
- public/javascripts/javascript_4.js
- public/javascripts/javascript_n.js
stylesheets:
workspace:
- public/stylesheets/style_1.css
- public/stylesheets/style_2.css
- public/stylesheets/style_3.css
- public/stylesheets/style_4.css
- public/stylesheets/style_n.css
common:
- public/stylesheets/style_1.css
- public/stylesheets/style_2.css
- public/stylesheets/style_n.css
global
- public/stylesheets/style_1.css
- public/stylesheets/style_2.css
- public/stylesheets/style_n.css
For Rails-3 make sure that you have the following line in your config/environment.rb, since by default the static asserts will not be served
config.serve_static_assets = true
Usage:
<%= include_stylesheets :common, :workspace, :media => 'all' %>
<%= include_javascripts :workspace %>
Step-2:
Add the heroku-jammit plugin to your Heroku by,
$ heroku plugins:install https://github.com/chebyte/heroku-jammit.git
Usage:
Whenever you change any javascript/css files configured in your asserts.yml file, you have to use any of the following tasks to make your changes get reflected.
$ heroku jammit:add
– this task will make the asserts and commit it.
$ heroku jammit:delete
– this task will remove asserts and commit it.
This will work fine.