0
votes

Ok, I know there are some post opened about similar issues, but I've devoted two/three days trying to solve this problem and I'm out of clue. I've developed an app on Rails 3.2.8 and deployed it to a Digital Ocean server using this tutorial: https://gorails.com/deploy/ubuntu/12.04

This involves deploying with Capistrano 3.1.0 on a server with Nginx and Passenger installed. Ruby is manager with rvm.

What happens: - css not loading, except application.css (only basic css coded on this file working) - js not loading - destroy/delete routes not working (caused propably by main js not being loaded) - The app works fine on development environment

What I've tried: - precompiling assets on production environment, connecting by ssh - precompiling assets on development environment, then pushing them to production - Checked that assets are generated and located on /current/public after that - try several config options of nginx - try several config options of production.rb - restarted nginx: sudo service nginx restart after each try

I think it has to be a configuration issue, but the chances to find it by myself are very low (this is the very first app I deploy on my own) so any help would be appreciated. Thanks 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 and Setup Up Stages
require 'capistrano/setup'

# Includes default deployment tasks
require 'capistrano/deploy'

# Includes tasks from other gems included in your 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 from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

/etc/nginx/sites-enabled/default

server {
        listen 80 default_server;
        listen [::]: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;

        # Some browsers still send conditional-GET requests if there's a
        # Last-Modified header or an ETag header even if they haven't
        # reached the expiry date sent in the Expires header.
            add_header Last-Modified "";
            add_header ETag "";
            break;
        }

        # redirect server error pages to the 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 that Capistrano precompilation is generating empty application .css and .js files. I've tryed to precompile assets on development and upload them, but seems Capistrano then precompile again after the deploy and assets are overwriten to empty files.

Any clue?

1
Check Nginx logs. Can you see incoming requests for assets? Are those requests correct (spelling, path)? Is Nginx returning 404?Substantial
/var/log/nginx/error.log appears to be empty. tail -f log/production.log seems not to be requesting assets...Prade Mismo
Started GET "/entries" for 213.27.137.58 at 2014-10-15 07:07:41 -0400 Processing by EntriesController#index as HTML Rendered layouts/_next_concert.html.haml (1.0ms) Rendered layouts/_social_network.html.haml (2.1ms) . . . Rendered layouts/_notices.html.haml (0.3ms) Rendered layouts/_copyright.html.haml (1.0ms) Completed 200 OK in 59ms (Views: 45.2ms | ActiveRecord: 5.8ms)Prade Mismo
So you say all the precompiled assets are there? Look at your HTML output - what do the asset filenames look like? Are they the same or different to what was precompiled? What does the FULL request URL look like?SnakeWasTheNameTheyGaveMe
Once the web is loaded, in the head appears some .css files requested, such as: href="/assets/anything-slider-dd5dc923ac634c7fa6d7b143be5670cd.css" These files are requested on application.html.haml: = stylesheet_link_tag "anything-slider"Prade Mismo

1 Answers

0
votes

I finally solved the problem, based in carefully research and helped by this question.

Always, when deploying the app using Capistrano got some indirect reference to RVM when compiling assets, so started to 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 by RVM on production server:

$ rvm use
Using /home/deploy/.rvm/gems/ruby-2.1.3

So, I tough it could some ruby version conflict? Chaged Ruby version of RVM:

$ rvm install 1.9.3
$ rvm use 1.9.3
$ rvm --default 1.9.3

Then, needed to install all gems and precompile the assets using the new settings:

$ bundle Install
$ RAILS_ENV=production bundle exec rake assets:precompile

Asset files application.js and application.css where succesfully created with all the content, and when restarted the web app, all was working fine!