Rails app on Nginx/Passenger/Capistrano: assets not working -
Rails app on Nginx/Passenger/Capistrano: assets not working -
ok, know there post opened similar issues, i've devoted two/three days trying solve problem , i'm out of clue. i've developed app on rails 3.2.8 , deployed digital ocean server using tutorial: https://gorails.com/deploy/ubuntu/12.04
this involves deploying capistrano 3.1.0 on server nginx , passenger installed. ruby manager rvm.
what happens: - css not loading, except application.css (only basic css coded on file working) - js not loading - destroy/delete routes not working (caused propably main js not beingness loaded) - app works fine on development environment
what i've tried: - precompiling assets on production environment, connecting ssh - precompiling assets on development environment, pushing them production - checked assets generated , located on /current/public after - seek several config options of nginx - seek several config options of production.rb - restarted nginx: sudo service nginx restart
after each try
i think has configuration issue, chances find myself low (this first app deploy on own) help appreciated. in advance.
config/environment/production.rb:
config.serve_static_assets = false config.assets.compress = true config.assets.compile = false config.assets.digest = true config.assets.precompile += ['grid.css'] config.assets.precompile += ['anything-slider.css'] config.assets.precompile += ['nivo-slider.css'] config.assets.precompile += ['jplayer.css'] config.assets.precompile += ['lightbox.css'] config.assets.precompile += ['reset.css'] config.assets.precompile += ['anything-slider.js'] config.assets.precompile += ['jplayer.playlist.min.js'] config.assets.precompile += ['jquery-1.11.0.min.js'] config.assets.precompile += ['jquery-ui.js'] config.assets.precompile += ['jquery.jplayer.min.js'] config.assets.precompile += ['jquery.js'] config.assets.precompile += ['jquery.mousewheel.js'] config.assets.precompile += ['jquery.nivo.slider.pack.js'] config.assets.precompile += ['lightbox.min.js'] config.assets.precompile += ['nivo-slider.js'] config.assets.precompile += ['populate_jplayer.js'] config.assets.precompile += ['quickstand.js'] config.assets.precompile += ['script.js'] config.assets.precompile += ['tooltipsy.js']
config/application.rb:
config.assets.enabled = true config.assets.initialize_on_precompile = false
capfile:
# load dsl , setup stages require 'capistrano/setup' # includes default deployment tasks require 'capistrano/deploy' # includes tasks other gems included in gemfile # require 'capistrano/bundler' require 'capistrano/rails' # require 'capistrano/rails/assets' # require 'capistrano/rails/migrations' require 'capistrano/rvm' set :rvm_type, :user set :rvm_ruby_version, '2.1.3' # loads custom tasks `lib/capistrano/tasks' if have defined. dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
/etc/nginx/sites-enabled/default
server { hear 80 default_server; hear [::]:80 default_server ipv6only=on; server_name porinstinto.com; passenger_enabled on; rails_env production; root /home/deploy/porinstinto/current/public; location ~* ^/assets/ { # per rfc2616 - 1 year maximum expiry # http://www.w3.org/protocols/rfc2616/rfc2616-sec14.html expires 1y; add_header cache-control public; # browsers still send conditional-get requests if there's # last-modified header or etag header if haven't # reached expiry date sent in expires header. add_header last-modified ""; add_header etag ""; break; } # redirect server error pages static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
application.js
// //= require jquery //= require jquery_ujs //= require anything-slider //= require jplayer.playlist.min //= require jquery-ui //= require jquery.jplayer.min //= require jquery.mousewheel //= require jquery.nivo.slider.pack //= require lightbox.min //= require nivo-slider //= require populate_jplayer //= require quickstand //= require script //= require tooltipsy //= require_tree .
application.css
* *= require anything-slider *= require grid *= require jplayer *= require lightbox *= require nivo-slider *= require reset *= require_self *= require_tree . */
update: i've discovered capistrano precompilation generating empty application .css , .js files. i've tryed precompile assets on development , upload them, seems capistrano precompile 1 time again after deploy , assets overwriten empty files.
any clue?
i solved problem, based in research , helped question.
always, when deploying app using capistrano got indirect reference rvm when compiling assets, started investigate that.
found ruby version of development environment:
$ ruby -v ruby 1.9.3p545 (2014-02-24 revision 45159) [x86_64-linux]
found ruby version used rvm on production server:
$ rvm utilize using /home/deploy/.rvm/gems/ruby-2.1.3
so, tough ruby version conflict? chaged ruby version of rvm:
$ rvm install 1.9.3 $ rvm utilize 1.9.3 $ rvm --default 1.9.3
then, needed install gems , precompile assets using new settings:
$ bundle install $ rails_env=production bundle exec rake assets:precompile
asset files application.js , application.css succesfully created content, , when restarted web app, working fine!
ruby-on-rails ruby-on-rails-3 nginx capistrano assets
Comments
Post a Comment