You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Rails中集成Bootstrap Tour报错:无法找到text/css类型的bootstrap-tour文件

Fixing "couldn't find file 'bootstrap-tour' with type 'text/css'" Error in Bootstrap Tour Rails

Let's break down how to resolve this error and get Bootstrap Tour working smoothly in your Rails app:

First, Understand the Root Cause

The error pops up because Sprockets (Rails' asset pipeline) can’t locate a plain CSS file named bootstrap-tour when using the *= require directive in your SCSS manifest. The bootstrap-tour-rails gem packages its styles as SCSS files, not raw CSS—so we need to use SCSS’s native @import instead.

Step 1: Fix the Stylesheet Import

Open your application.scss file and replace the problematic require directive with an SCSS import:

/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
* *= require_tree .
*= require_self
*/
// Replace the *= require bootstrap-tour line with this import
@import "bootstrap-tour";

Step 2: Fix JavaScript Loading Order

Looking at your application.js, you’re loading bootstrap-tour before bootstrap-sprockets—this can cause bugs since Bootstrap Tour depends on Bootstrap’s core components (like modals or tooltips). Adjust the order to load Bootstrap first:

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require popper
//= require tether
//= require bootstrap-sprockets
//= require bootstrap-tour
//= require_tree .

Step 3: Verify and Restart

  1. Save both modified files
  2. Restart your Rails server (this ensures the asset pipeline picks up the changes properly)
  3. Clear your browser cache or do a hard refresh (Ctrl+Shift+R or Cmd+Shift+R) to load the updated assets

Why This Works

  • Using @import in SCSS tells the preprocessor to look for SCSS files in the gem’s asset directories, which matches how bootstrap-tour-rails packages its styles.
  • Loading Bootstrap’s JS first ensures all dependencies that Bootstrap Tour relies on are available when it initializes.

内容的提问来源于stack exchange,提问作者csandrid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:38:51