gpt4 book ai didi

css - Bootstrap 不路由 CSS 或 JavaScript?没有路由匹配 [GET] "/css/bootstrap.css"

转载 作者:太空宇宙 更新时间:2023-11-04 13:15:14 25 4
gpt4 key购买 nike

  • rails 4.1.1
  • ruby 2.0
  • Webrick 服务器

我正在尝试让 bootstrap-sass 在开发中第一次工作。我尝试按照 GitHub 说明、Bootstrap 网站说明和其他几个视频进行操作,看起来我可以安装 gem、拖放文件、更新 application.css.scss 文件和在应用程序索引页面中引用 css 文件,在 View 中调用一些 css,它会起作用。

当我检查页面的源代码(其中包含我放入 application.index.erb 文件中的 Bootstrap 引用)以确认 Bootstrap 正在运行时,出现错误。代码在那里,但我点击 css 链接以确认它的工作并得到这个:

No route matches [GET] "/css/bootstrap.css"

这是我的 application.css.scss 文件:

/*
* 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 vendor/assets/stylesheets of plugins, if any, 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 styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/

@import "bootstrap-sprockets"
@import "bootstrap"

即使我处于开发模式,我也将生产文件设置为:

  config.serve_static_assets = true

一定是路由问题,但我无法弄清楚为什么我的 Assets 管道无法在开发模式下使用 css 和 js?

此外,这是我的 gem 文件:

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.1'
# Use mysql as the database for Active Record
gem 'mysql2'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Bootstrap-sass - Latest Version for Web Design (CSS and HTML Layout)
gem 'bootstrap-sass', '~> 3.2.0'
# Vendor Prefixes
gem 'autoprefixer-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Simple_form - Forms made easy! Top form generator on ruby-toolbox.com
gem 'simple_form'

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

[更新]

这是完整的错误页面 [url 是:http://localhost:3000/css/bootstrap.css#]:

Routing Error
No route matches [GET] "/css/bootstrap.css"

Rails.root: C:/Users/Kevin/Desktop/sites/solar_permit

Application Trace | Framework Trace | Full Trace
Routes

Routes match in priority from top to bottom

Helper HTTP Verb Path Controller#Action
Path / Url
root_path GET / projects#index
projects_path GET /projects(.:format) projects#index
POST /projects(.:format) projects#create
new_project_path GET /projects/new(.:format) projects#new
edit_project_path GET /projects/:id/edit(.:format) projects#edit
project_path GET /projects/:id(.:format) projects#show
PATCH /projects/:id(.:format) projects#update
PUT /projects/:id(.:format) projects#update
DELETE /projects/:id(.:format) projects#destroy
GET|POST /:controller(/:action(/:id))(.:format) :controller#:action

这是应用程序布局文件:

<!DOCTYPE html>
<html>
<head>
<title>SolarPermit</title>
<link href="/css/bootstrap.css" rel="stylesheet" media="screen">
</head>
<body>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="js/bootstrap.js"></script>
<div class="container">
<ul class="nav nav-tabs">
<li><%= link_to "Home", root_path %></li>
</ul>
<%= yield %>
</div>

</body>
</html>

最佳答案

所以我设法通过以下方式解决了这个问题:

ExecJS::RuntimeError in Users#index (RoR)

尽管它说删除“//= require_tree”忽略了这个问题,但我四处走动试图修复在我安装 node.js 并更改 UTF 信息后不断出现的 ExecJS 错误16 到 8。我删除了 require_tree 评论,尽管有人建议我绕过它。

我敢肯定以后会有更多错误,但根据我的研究,Windows 和 ExecJS 似乎存在不兼容问题。我是 Ruby 的新手,所以我认为它真的与与之关联的 gem 有关吗?例如,我尝试了 therubyracer gem(如其他帖子所建议的那样)并需要 gems 但它想要安装 python 但失败了。

无论如何,我进一步阅读,ExecJS 和 Windows 有很多问题,似乎可以通过过渡到基于 linux 的开发服务器来解决。

无论哪种方式,这现在对我有用。

关于css - Bootstrap 不路由 CSS 或 JavaScript?没有路由匹配 [GET] "/css/bootstrap.css",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24440127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com