首页 > 解决方案 > Rails5没有路线匹配[GET]“/bootstrap/css/bootstrap.min.css”

问题描述

我在下面写一个页面:

<head> 
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">

<title>Shop Homepage - Start Bootstrap Template</title>

<!-- Bootstrap core CSS -->
<link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="/shop-homepage.css" rel="stylesheet">

</head>

我得到了这个错误:

Started GET "/shop-homepage.css" for ::1 at 2020-11-22 17:21:15 +0800
Started GET "/bootstrap/css/bootstrap.min.css" for ::1 at 2020-11-22 17:21:15 +0800
ActionController::RoutingError (No route matches [GET] "/shop-homepage.css"):
ActionController::RoutingError (No route matches [GET] "/bootstrap/css/bootstrap.min.css"):
Started GET "/css/shop-homepage.css" for ::1 at 2020-11-22 17:21:15 +0800

我的资产是这样的

结构体

我已经编辑了application.scss。我的资产在 Rails 的路径中。

 @import "bootstrap-sprockets";
 @import "bootstrap";
 @import "../css/shop-homepage.css";

为什么它只是找不到 .css

标签: cssruby-on-rails

解决方案


对于 Rails 5 ,我强烈建议使用 gem,而不是尝试自己导入引导文件。

这是标准方法:

https://github.com/twbs/bootstrap-rubygem


推荐阅读