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

localhost:3000 will not update my css, or will not load at all when static files are deleted of switch off

自从我预编译要部署到 Heroku 的资产以来,我一直在努力处理我的 rails 项目。 css 不会更新,所以我按照其他类似条目的建议删除了静态文件。该应用程序将永远不会加载,它只会处于缓冲状态。我还尝试简单地将 config.serve_static_files 设置为 false。在 运行 清理资产后,我得到了相同的结果。我也试过 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

请帮助我,我很难做这样的工作。谢谢

你试过了吗运行rake assets:precompile

一些小知识给你:

rake assets:clean

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

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

--

又一则琐事:

每当 运行ning rake assets:precompile, 运行 它带有一个 ENV var:

rake assets:precompile RAILS_ENV=production

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


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

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

这样做的原因是,如果您在开发中处理预编译资产,则每次要测试它们是否已更改时都必须重新编译它们,既耗时又不可靠。

Heroku 应该只需要对其 production 环境进行资产预编译。


I cannot even run that it seems

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

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

  1. 将所有 CSSJS 删除到临时文件夹(如有必要,Recycle Bin),然后 运行 rake assets:precompile .可能有一个关闭 reference/loop 导致问题

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

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

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

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