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

  显示原文与译文双语对照的内容
0 0
  • Rails 4.1.1
  • ruby 2.0
  • Webrick服务器

我正在努力让 bootstrap-sass 在开发中首次工作。 在这个例子中,我尝试在视图中安装 gem 。拖拽文件。在视图中调用css文件,在视图中调用一些 css 。

当我检查( 我把 Bootstrap 引用放在 application.index.erb 文件里了)的源代码以确认 Bootstrap 正在工作时,我得到了一个错误。 代码在那里,但是我点击css链接来确认它的工作并得到它:


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

这是我的application.css.scss file:


/*
 * 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

必须有一些路由问题,但是我不知道为什么我的资产管道不会使css和js可以用。

这是我的gem file:


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]

[UPDATE ]

下面是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

下面是应用程序布局 file:


<!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>

时间: 原作者:

0 0

这不是在 Rails 中包含资产的方法。 你的bootstrap.css 位于哪里?

你可以使用这里( 这是没有turbolinks的),而不是 `/css/bootstrap.css'和'js/bootstrap 。js',包括你的完整资产库:


<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
<%= csrf_meta_tags %>

这是用turbolinks写的:


<%= stylesheet_link_tag 'application', media: 'all', :"data-turbolinks-track" => true %>
<%= javascript_include_tag 'application', :"data-turbolinks-track" => true %>
<%= csrf_meta_tags %>

如果只希望包含 上面 文件( application.css.scss ),则应添加:


<link href="/assets/application.css" rel="stylesheet" media="screen">

其中包括 Bootstrap 。

另一方面,我认为应该将 @import 指令保留在 application.css 文件中,这样不应该命名为 application.css.scss

然后,在新文件( 例如 main.css. scss ) 中添加 @import 指令。 这是最常见的方法,我认为正确的方法。 所以:

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
 */

main.css.scss:


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

原作者:
0 0

因此,我已经通过以下方法解决了这个问题:

Users#index ( RoR ) 中的 ExecJS::RuntimeError

我在安装"//= 之后一直在尝试修复ExecJS错误,并从 16到 8修改了UTF信息,但这一事实却忽略了这个问题。 尽管建议我绕过了require_tree注释,但我删除了它。

我相信路上会有更多的错误,但是基于我的研究,Windows 和ExecJS有一个不兼容性问题。 我对 ruby 是新的,所以我认为它与与它相关联的gem 真的有一些? 例如我尝试了 therubyracer gem ( 如其他帖子所建议) 和必需的Gems,但它需要 python 安装并失败。

总之,我进一步阅读了ExecJS和 Windows的许多问题,似乎通过转换到基于linux的开发服务器解决了很多问题。

不管怎样这对我来说都是有效的。

...