localhost:3000不会更新我的css,或者当静态文件被删除关闭时根本不会加载

时间:2015-09-27 06:01:43

标签: css ruby-on-rails localhost assets

我一直在尝试处理我的rails项目,因为我预先编译了要部署到Heroku的资产。 css不会更新,所以我按照其他类似条目的建议删除了静态文件。然后应用程序将永远不会加载,它将处于缓冲状态。我还尝试将config.serve_static_files设置为false。运行rake资产后,我得到了相同的结果。我也试过dscacheutil -flushcache,没效果。

我的development.rb文件:

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

      # In the development environment your application's code is reloaded on
      # every request. This slows down response time but is perfect for development
      # since you don't have to restart the web server when you make code changes.
      config.cache_classes = false

      # Do not eager load code on boot.
      config.eager_load = false

      # Show full error reports and disable caching.
      config.consider_all_requests_local       = true
      config.action_controller.perform_caching = false

      # Don't care if the mailer can't send.
      config.action_mailer.raise_delivery_errors = false

      # Print deprecation notices to the Rails logger.
      config.active_support.deprecation = :log

      # Raise an error on page load if there are pending migrations.
      config.active_record.migration_error = :page_load

      # Debug mode disables concatenation and preprocessing of assets.
      # This option may cause significant delays in view rendering with a large
      # number of complex assets.
      config.assets.debug = false
      config.serve_static_files = false

      # Asset digests allow you to set far-future HTTP expiration dates on all assets,
      # yet still be able to expire them through the digest params.
      config.assets.digest = true
      config.assets.compress = true
      # Adds additional error checking when serving assets at runtime.
      # Checks for improperly declared sprockets dependencies.
      # Raises helpful error messages.
      config.assets.raise_runtime_errors = false

      # Raises error for missing translations
      # config.action_view.raise_on_missing_translations = true
    end

以防我的production.rb文件:

    Rails.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

      # Eager load code on boot. This eager loads most of Rails and
      # your application in memory, allowing both threaded web servers
      # and those relying on copy on write to perform better.
      # Rake tasks automatically ignore this option for performance.
      config.eager_load = true

      # Full error reports are disabled and caching is turned on.
      config.consider_all_requests_local       = false
      config.action_controller.perform_caching = true

      # Enable Rack::Cache to put a simple HTTP cache in front of your application
      # Add `rack-cache` to your Gemfile before enabling this.
      # For large-scale production use, consider using a caching reverse proxy like
      # NGINX, varnish or squid.
      # config.action_dispatch.rack_cache = true

      # Disable serving static files from the `/public` folder by default since
      # Apache or NGINX already handles this.
      config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?

      # Compress JavaScripts and CSS.
      config.assets.js_compressor = :uglifier
      # config.assets.css_compressor = :sass

      # Do not fallback to assets pipeline if a precompiled asset is missed.
      config.assets.compile = false

      # Asset digests allow you to set far-future HTTP expiration dates on all assets,
      # yet still be able to expire them through the digest params.
      config.assets.digest = true

      # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

      # 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

      # Use the lowest log level to ensure availability of diagnostic information
      # when problems arise.
      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'

      # Ignore bad email addresses and do not raise email delivery errors.
      # Set this to true and configure the email server for immediate delivery to raise delivery errors.
      # config.action_mailer.raise_delivery_errors = false

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

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

      # Use default logging formatter so that PID and timestamp are not suppressed.
      config.log_formatter = ::Logger::Formatter.new

      # Do not dump schema after migrations.
      config.active_record.dump_schema_after_migration = false
    end

请帮助我,我几乎不能做这样的工作。谢谢

2 个答案:

答案 0 :(得分:3)

您是否尝试过rake assets:precompile

答案 1 :(得分:1)

有些琐事:

rake assets:clean

摆脱所有预编译资产的更好方法是rake assets:clobber

这会主动删除/public/assets文件夹中的文件和文件夹,从而可以删除任何可能遗留的预编译资产。

-

另一件琐事:

每当运行rake assets:precompile时,使用ENV var:

运行它
rake assets:precompile RAILS_ENV=production

这确保使用数据和文件预编译文件。 production 环境中可用的设置,从而为您提供最可靠的文件。

作为我自己的规则,我总是尝试确保动态加载本地资产。

这不需要您做任何更改(实际上,我实际上删除了serve_static_files文件中的development.rb行。

这样做的原因是,如果您在开发中处理预编译资产,那么每次要测试它们是否已经发生变化时都需要重新编译它们,既耗时又不可靠。

Heroku只应为其生产环境要求资产预编译。

  

我甚至无法运行它似乎

这表明您的应用程序或Ruby安装存在更深层次的问题。

您需要做几件事来确保这不是一个主要问题:

  1. 将所有CSSJS移至临时文件夹(如有必要,Recycle Bin),然后运行rake assets:precompile。可能存在导致问题的关闭引用/循环

  2. 使用rails new TESTAPP创建新的Rails应用,然后立即运行rake assets:precompile。如果它运作良好,您知道问题出在您当前的应用程序

  3. 停止任何其他正在运行的进程。如果您运行的程序可能阻碍cmd,那么它将阻止它顺利运行。

  4. 如果你使用RubyInstaller之类的东西安装你的Ruby,你可能希望升级。如果没有,您可能希望升级。

  5. 最终,如果您的计算机处理rake命令的速度非常慢,则表明存在重大系统问题。您需要确保它正常工作以确保平稳的开发周期。