【发布时间】:2014-07-30 11:27:46
【问题描述】:
我对此束手无策。似乎所有较新的 Rails 应用程序我都在environments/production.rb 中设置了几个配置,部署并继续我的生活。但是现在我们正在将一些 Rails 应用程序迁移到新服务器上,并且在部署到生产环境时似乎所有这些应用程序都存在这个问题。
似乎正在发生的事情是我的 javascripts 或样式表都没有被编译。而且我看不到应用程序的任何样式,并且 javascript 不起作用。
config/application.rb:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
Bundler.require(:default, :assets, Rails.env)
end
module MyApp
class Application < Rails::Application
... omitted code ...
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
config.generators.stylesheet_engine = :scss
end
end
config/environments/production.rb:
MyApp::Application.configure do
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
# Generate digests for assets URLs
config.assets.digest = true
... omitted code ...
end
在我的应用程序中-<...>.js:
// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require_tree
;
而我的应用程序-<...>.css 完全是空的。我错过了什么?
【问题讨论】:
-
有什么问题?我假设样式没有从开发服务器反映到生产服务器?
-
您好,您是否在新服务器上设置了 javascript 环境来编译您的资产? (例如nodejs)。如果没有将 therubyracer 添加到您的 Gemfile 中并进行测试。
-
是的,CSS 和 javascript 在生产环境中都不起作用。我正在使用 'therubyracer' gem 作为资产
gem 'execjs', gem 'therubyracer', :platforms => :ruby gem 'libv8', '3.3.10.4'
标签: ruby ruby-on-rails-3.2 asset-pipeline production-environment