html - 响应式 Bootstrap 不会预编译

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

我不太熟悉 HTML 的内部工作原理。我太依赖 Bootstrap 了,无法为我发挥它的魔力,所以我终于找到了一个让我完全难过的地方。我需要使我的应用程序的 View 具有响应性,以检测与其连接的设备屏幕的分辨率。在我的本地机器上,这很好。我在我的 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

最佳答案

首先,您不必像这样将路径放在 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 )

关于html - 响应式 Bootstrap 不会预编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18087503/

相关文章:

javascript - 关联点击事件和多个item,没有multiple functions

html - 文本离 iframe 太近 - 如何在它周围获得边距/边框?

jquery - Bootstrap-slider 自定义句柄

css - 将子 div 在父级中居中/底部对齐

ruby-on-rails - '需要': cannot load such file -- 'nokogiri\nokogiri' (LoadError) when running `rails server`

html - 水平对齐图像和标题标题 (div),并将宽度添加到 hr (NO TABLE)

javascript - 网页抓取 : finding all contents when specific part of HTML is changing repeatedly

ruby-on-rails - Ruby on Rails捕获摄像头视频和音频

ruby-on-rails - rails : dotenv nested hash

javascript - JQuery - 在屏幕上单击并拖动 div 而无需拖动