响应式Bootstrap不会预编译

时间:2013-08-06 18:14:18

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

我不太熟悉HTML的内部工作原理。我依靠Bootstrap有点过分为我的魔法工作,所以我终于找到了一个我完全难倒的地方。我需要为我的应用程序生成视图,以响应检测连接到它的设备屏幕的分辨率。在我的本地机器上,这很好。我在第三个stylesheet_link_tag添加了layout/application.html.haml文件,如下所示,以及其后面的%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

1 个答案:

答案 0 :(得分: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 )