The problem is this: everything works fine in development, but when I deploy the rails application for production, the site works in plain html, but CSS (bootstrap) doesn't load (JS probably doesn't either).
Sorry, I was looking for 2 days on ~ 15 possible solutions and could not get it to work ...
Update: After you follow @ rich-peck's advice, this seems like a server issue. Updated using nginx configuration
My setup:
- Ruby 2.1.2, Rails 4.1
- Rbenv
- mysql2 as db
- Bootstrap 3
- Ubuntu 14.04 on a server with nginx and passenger
- Capistrano 3 for deployment
Configure as follows - production.rb:
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = true
config.assets.compress = true
config.assets.compile = false
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :info
config.assets.precompile << /(^[^_\/]|\/[^_])[^\/]*$/
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
Capfile:
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/rails'
require 'capistrano/rbenv'
set :rbenv_type, :user
set :rbenv_custom_path, '/home/deploy/.rbenv/'
set :rbenv_ruby, '2.1.2'
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
in application.rb:
...
config.assets.enabled = true
...
application.css.scss:
@import "bootstrap";
@import "custom";
@import "exchange_rates";
@import "contacts";
, ( ):
RAILS_ENV=production bundle exec rake assets:precompile
. CSS Javascript Rails
:
config.serve_static_assets = true # tried false
config.assets.compile = false # tried true
. rails css/js/images
production.log , js.
Rails Asset Pipeline nginx, ... !
: nginx
gorails: https://gorails.com/deploy/ubuntu/14.04
nginx , ( SO) :
/etc/nginx/nginx.conf:
events {
worker_connections 4096;
}
http {
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /home/deploy/.rbenv/shims/ruby;
passenger_nodejs /usr/bin/nodejs;
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name <URL>;
passenger_enabled on;
rails_env production;
root /home/deploy/<PROJECT_NAME>/current/public;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
(URL PROJECT_NAME )
/etc/nginx/sites-enabled/default , nginx - . - - ?