2013-04-03 74 views
0

我有一個基於jquery和rails3-jquery-autocomplete gem的提前輸入下拉列表。我不得不添加一些文件到app/assets/javascript和app/assets/stylesheets。我已經指出了在dev和prod模式下運行應用程序的問題。有沒有人有這方面的經驗,並可以告訴我在config/envrionments/production.rb中更改哪些設置。我對理解資產管道非常困難。Jquery在開發模式下工作,但沒有生產

這是我製作的配置文件:

Dcms::Application.configure do 

    # Settings specified here will take precedence over those in config/application.rb 

    # 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 
    config.serve_static_assets = true 

    # 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 

    # Defaults to nil and saved in location specified by config.assets.prefix 
    # config.assets.manifest = YOUR_PATH 

    # Specifies the header that your server uses for sending files 
    # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 
    # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 

    # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 
    # config.force_ssl = true 

    # See everything in the log (default is :info) 
    # config.log_level = :debug 

    # Prepend all log lines with the following tags 
    # config.log_tags = [ :subdomain, :uuid ] 

    # Use a different logger for distributed setups 
    # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 

    # Use a different cache store in production 
    # config.cache_store = :mem_cache_store 

    # Enable serving of images, stylesheets, and JavaScripts from an asset server 
    # config.action_controller.asset_host = "http://assets.example.com" 

    # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) 
    # config.assets.precompile += %w(search.js) 

    # Disable delivery errors, bad email addresses will be ignored 
    # config.action_mailer.raise_delivery_errors = false 

    # Enable threaded mode 
    # config.threadsafe! 

    # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 
    # the I18n.default_locale when a translation can not be found) 
    config.i18n.fallbacks = true 

    # Send deprecation notices to registered listeners 
    config.active_support.deprecation = :notify 

    # Log the query plan for queries taking more than this (works 
    # with SQLite, MySQL, and PostgreSQL) 
    # config.active_record.auto_explain_threshold_in_seconds = 0.5 
end 
+0

當JavaScript從開發到生產停止使用Rails時,問題很可能與您的資產在生產中預編譯有關。首先要看看您的瀏覽器在您的JavaScript控制檯中,以查看頁面加載時或者開始嘗試自動完成時是否發生錯誤。如果你正在做服務器端/ ajax自動完成,你還應該檢查你的服務器日誌,看看請求是否進來。 – atw13 2013-04-03 20:49:00

+0

謝謝。錯誤發生在我的頁面加載時。它表示「Uncaught TypeError:無法讀取未定義的屬性'原型'」。我不明白這個。 – 2013-04-03 21:01:07

+0

如果你的代碼沒有深入到底,這真的很難說,但編譯資產的一個潛在缺陷是你的javascript代碼出現在最終壓縮的.js文件中的順序。確保你所有的包含js文件的js文件都有像jquery這樣的沉重的庫文件,如果你包含整個文件夾,確保代碼在文件按字母順序讀取時工作。 – atw13 2013-04-03 21:48:37

回答

1

如果JS資產被連接在一起,請檢查是否每個文件末尾有「;」 。此外,你也可以添加一個「;」在每個JS文件開始避免前一個人期待什麼是一個沒有返回的函數的參數或有些別的。

說明

文件a.js

(function() {})() 

文件b.js

(function() {})() 

現在CONCAT什麼返回第一個函數發現括號,並承認這應該是一個函數。

+0

這是關於自動完成的正確答案。在這裏晚些時候發聲,但@Joe可能需要添加一些函數 - add_fields和remove_fields - 並且我發現的引用缺少分號 – Jerome 2015-09-05 17:46:07

相關問題