【问题标题】:Responsive Bootstrap won't precompile响应式 Bootstrap 不会预编译
【发布时间】:2013-08-06 18:14:18
【问题描述】:

我不太熟悉 HTML 的内部工作原理。我过于依赖 Bootstrap 来为我发挥它的魔力,所以我终于找到了一个让我完全难过的地方。我需要让我的应用程序的视图响应检测连接到它的设备屏幕的分辨率。在我的本地机器上,效果很好。我在我的layout/application.html.haml 文件中添加了第三个stylesheet_link_tag,如下所示,以及它后面的%meta 行。

!!!
%html
  %head
    %title WallyWorld
    = stylesheet_link_tag    "application", :media => "all"
    = stylesheet_link_tag    "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css"
    = stylesheet_link_tag    "assets/css/bootstrap-responsive.css", :rel => 'stylesheet/less'
    = javascript_include_tag "application"
    = csrf_meta_tags
    %meta{:content => "width=device-width, initial-scale=1.0", :name => "viewport"}
  %body
    // The rest...

再一次,这对我来说很多都没有意义。尽我所能跟随documentation

在我的本地机器上一切正常。但是,当我cap deploy 它并在生产机器上启动unicorn 服务器时,我收到以下错误:

2013-08-06 12:57:54 FATAL -- 
ActionView::Template::Error (assets/css/bootstrap-responsive.css isn't precompiled):
  4:     %title WallyWorld
  5:     = stylesheet_link_tag    "application", :media => "all"
  6:     = stylesheet_link_tag    "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css"
  7:     = stylesheet_link_tag    "assets/css/bootstrap-responsive.css", :rel => 'stylesheet/less'
  8:     = javascript_include_tag "application"
  9:     = csrf_meta_tags
  10:     %meta{:content => "width=device-width, initial-scale=1.0", :name => "viewport"}
app/views/layouts/application.html.haml:7:in `_app_views_layouts_application_html_haml__3068307506204356330_32376380'

好的,太好了。 bootstrap-responsive.css 未预编译。好吧,我实际上不知道如何手动执行此操作。我尝试按照this article 的建议下载我自己的自定义版本的 Bootstrap,但我现在更加困惑。我完全不知道如何让这些东西发挥作用。

任何关于使这些东西工作的实际过程的建议或解释都会很棒。奇怪的是,很难找到一个解释,至少在我能理解的方面。

==== 编辑添加到 production.rb ====

Wallyworld::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

  # Compress JavaScripts and CSS
  config.assets.compress = true

  # Don't fallback to assets pipeline if a precompiled asset is missed
  config.assets.compile = false

  # 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( assets/css/bootstrap-responsive.css )

  # 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

【问题讨论】:

    标签: html css ruby-on-rails twitter-bootstrap responsive-design


    【解决方案1】:

    首先,您不必像这样将路径放在stylesheet_link_tag 中。做吧:

    <%= stylesheet_link_tag 'bootstrap-responsive' %>
    

    在您的config/envinronments/production.rb 文件中,找到相关设置:

    # config.assets.precompile += %w( search.js )

    取消注释并将未预编译的文件添加到数组中:

    config.assets.precompile += %w( bootstrap-responsive.css )

    【讨论】:

    • 添加 bootstrap-responsive.cssassets/css/bootstrap-responsive.css 仍然给我同样的错误。
    • 你能发布整个production.rb 文件吗?你在 Heroku 上部署吗?您的 Capfile 是否在部署时预编译资产?
    • 我添加了文件。不,我正在部署到我拥有的服务器。此外,如果有帮助,我将无法再在本地计算机上运行该应用程序。我在我的引导文件中移动,根本无法让原始应用程序出现。现在一切都在抱怨bootstrap-responsive.css 文件。
    • 即使在开发中也不运行?你得到什么错误?顺便说一句,您的文件有误,应该是bootstrap-responsive.css。如果需要,您还可以通过 rake assets:precompile 在本地预编译资产。
    • 抱歉,只是想再次检查开发。它在那里工作得很好。是生产环境搞砸了。要回答您之前的问题,是的,Capfile 会预编译资产。但我什至不能在本地机器上手动编译我的资产并让它在生产中启动。总是失败。我将production.rb 文件改回bootstrap-responsive.css,但它仍然抛出未预编译的错误。我还手动运行 assets:precompile 生产任务。嗯……
    猜你喜欢
    • 1970-01-01
    • 2013-12-15
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-04
    • 1970-01-01
    相关资源
    最近更新 更多