0

我在這個智慧的結尾。似乎所有新的rails應用程序我都在environments/production.rb中設置了幾個配置,部署並繼續我的生活。但是現在我們正在將幾個Rails應用程序遷移到新的服務器上,而且在部署到生產環境時似乎所有人都有這個問題。Rails 3.2生產中的資產

似乎正在發生的事情是,我的JavaScript或樣式表都沒有被編譯。而且我看不到應用程序的樣式,而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 

配置/環境/ 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是完全空的。我錯過了什麼?

+0

有什麼問題?我假設造型沒有被反映到開發生產服務器? – coletrain

+0

嘿,你有沒有在你的新服務器上設置javascript env來編譯你的資產? (例如nodejs)。如果沒有將therubyracer添加到您的Gemfile中並進行測試。 – cristian

+0

是的CSS和JavaScript都不能在生產中工作。我使用'therubyracer'gem作爲資產 'gem'execjs',gem'therubyracer',:platforms =>:ruby gem'libv8','3.3.10.4'' – Sparkmasterflex

回答

0

因此,昨天過了大半天,今天大約一個小時,我突然意識到了一些事情......我之前遇到過這個問題。

果然......將rails更新到3.2.14並再次部署固定了整個事情。