documentcloud / jammit

Industrial Strength Asset Packaging for Rails
http://documentcloud.github.com/jammit/
MIT License
1.16k stars 197 forks source link

Jammit in production: undefined method `include_javascripts' #238

Closed ggrillone closed 11 years ago

ggrillone commented 11 years ago

I keep getting the following error in my production.log file: undefined method `include_javascripts', when using jammit it production. I created a rake task to minify the assets during deployment. Maybe my code is wrong, any suggestions?

Rake task:

require 'rake'

desc 'jammit'
  task :jam  => :environment do
  require 'jammit'
  Jammit.package!
end

Capistrano task:

before 'deploy:symlink_config', 'deploy:jammit'

namespace :deploy do
  desc "Run jammit to minify js files"
    task :jammit, roles: :app do
      run "cd #{deploy_to}/current && rake jam RAILS_ENV=production"
  end
end
jashkenas commented 11 years ago

Are you loading Jammit correctly when booting your Rails app? If you open a Rails console and type Jammit, is it there?

ggrillone commented 11 years ago

Yes on my localhost. Did you mean on the server? When executing cap deploy, it says jammit command finished successfully.

Also just noted in the jammit it docs (http://documentcloud.github.com/jammit/#configuration), it says if using nginx, add the following inside of server { ... }:

location ~ ^/assets/ {
  passenger_enabled on;
  expires max;
}

Tried it but when restarting nginx got a "nginx: [emerg] unknown directive "passenger_enabled"", assuming it's because I'm using unicorn, so if I change to 'unicorn_enabled on;' should that work?

ggrillone commented 11 years ago

Also, here's my assets.yml configuration in case it might be an issue with that:

package_assets: always
compress_assets: on
embed_assets: off
gzip_assets: off
javascript_compressor: uglifier
javascripts:
  globals:
    - .js files....
jashkenas commented 11 years ago

Yep -- when opening a console on the server. If you're not using passenger, don't worry about the nginx configuration.

ggrillone commented 11 years ago

When I run jammit, it pauses for a second or 2 (i'm assuming minifying files), and then returns the command prompt

ggrillone commented 11 years ago

Maybe I'm simply running the jam task too early or late? According to the docs "In production, you'll want to run Jammit during deployment, somewhere in between updating the source and symlinking to the new release"

Oh wait, just realized it is run before: deploy:update_code, so I'll have to try and run it after that

jashkenas commented 11 years ago

I don't think this has anything to do with the jammit task. I think this has to do with not loading the library correctly in your app on the server. Anyhow -- I probably can't be of much help to you, I'm afraid. Good luck debugging.

ggrillone commented 11 years ago

hmmm... so the strangest thing happened.. So we set-up a new staging server, with the exact same configurations as the production server. I didn't change any of the code that I've mentioned here, except this time jammit did work? Any ideas why this could be?

ParthivPatel-BTC commented 10 years ago

My jammit CSS and JS doesn't load. I am getting following error on DigitalOcean.

ActionView::Template::Error (undefined method include_stylesheets' for #<#<Class:0x000000041900b0>:0x00000004196fa0>): 2: %html 3: %head 4: %title= Settings.app_name 5: = include_stylesheets :canvas, :media => 'all' 6: = include_javascripts :canvas 7: = javascript_include_tag 'home/custom.js.coffee' 8: = csrf_meta_tags app/views/layouts/home.html.haml:5:in_app_views_layouts_home_html_haml__2155835962579908780_34422980' app/controllers/website/home_controller.rb:11:in `home'

I followed http://stackoverflow.com/questions/24554448/jammit-gem-error-on-production these steps but same result. Any Solution??