2013-04-03 78 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

相关问题