无法在 Bootstrap 中加载资源
Failed to load resource in Bootstrap
我正在使用 Bootstrap-sass (3.3.5, 3.3.1.0, 3.2.0.2)
我的字体文件保存在以下路径:
app/assets/fonts/bootstrap
glyphicons-halflings-regular.eot
glyphicons-halflings-regular.svg
glyphicons-halflings-regular.ttf
glyphicons-halflings-regular.woff
当我呈现页面时,出现此错误:
Started GET "/fonts/glyphicons-halflings-regular.ttf" for 127.0.0.1 at 2016-03-09 14:50:55 -0600
ActionController::RoutingError (No route matches [GET] "/fonts/glyphicons-halflings-regular.ttf"):
actionpack (4.1.7) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.7) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.7) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.7) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.7) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.7) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.7) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.5) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.7) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/static.rb:84:in `call'
rack (1.5.5) lib/rack/sendfile.rb:112:in `call'
railties (4.1.7) lib/rails/engine.rb:514:in `call'
railties (4.1.7) lib/rails/application.rb:144:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
rack (1.5.5) lib/rack/content_length.rb:14:in `call'
rack (1.5.5) lib/rack/handler/webrick.rb:60:in `service'
/Users/andreucasadella/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/Users/andreucasadella/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/Users/andreucasadella/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Rendered /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.7/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.0ms)
Rendered /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.7/lib/action_dispatch/middleware/templates/routes/_route.html.erb (22.7ms)
Rendered /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.7/lib/action_dispatch/middleware/templates/routes/_table.html.erb (4.6ms)
Rendered /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.7/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (146.0ms)
我也试过将它们移动到:
app/assets/fonts
但还是失败了。
您是否在 config/application.rb
中配置了资产路径以加载 app/assets/fonts
目录?
如果没有,你可以添加这样的内容:
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
完成后,您还应该从 public 已编译资产目录中将字体加载到 sass/less/css/whatever 文件中。例如在 sass 中,您可以使用助手 asset-url
:
@font-face {
font-family: 'MyFont';
src: asset-url('myfont.eot');
src: asset-url('myfont.eot?#iefix') format('embedded-opentype'),
asset-url('myfont.woff2') format('woff2'),
// etc ...
}
您可以在此处详细了解资产的工作原理:http://guides.rubyonrails.org/asset_pipeline.html
我在 public 目录中添加了一个字体文件夹:
public/fonts/glyphicons-halflings-regular.eot
public/fonts/glyphicons-halflings-regular.svg
public/fonts/glyphicons-halflings-regular.ttf
public/fonts/glyphicons-halflings-regular.woff
这解决了问题。
我正在使用 Bootstrap-sass (3.3.5, 3.3.1.0, 3.2.0.2)
我的字体文件保存在以下路径:
app/assets/fonts/bootstrap
glyphicons-halflings-regular.eot
glyphicons-halflings-regular.svg
glyphicons-halflings-regular.ttf
glyphicons-halflings-regular.woff
当我呈现页面时,出现此错误:
Started GET "/fonts/glyphicons-halflings-regular.ttf" for 127.0.0.1 at 2016-03-09 14:50:55 -0600
ActionController::RoutingError (No route matches [GET] "/fonts/glyphicons-halflings-regular.ttf"):
actionpack (4.1.7) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.7) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.7) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.7) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.7) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.7) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.7) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.5) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.7) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/static.rb:84:in `call'
rack (1.5.5) lib/rack/sendfile.rb:112:in `call'
railties (4.1.7) lib/rails/engine.rb:514:in `call'
railties (4.1.7) lib/rails/application.rb:144:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
rack (1.5.5) lib/rack/content_length.rb:14:in `call'
rack (1.5.5) lib/rack/handler/webrick.rb:60:in `service'
/Users/andreucasadella/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/Users/andreucasadella/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/Users/andreucasadella/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Rendered /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.7/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.0ms)
Rendered /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.7/lib/action_dispatch/middleware/templates/routes/_route.html.erb (22.7ms)
Rendered /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.7/lib/action_dispatch/middleware/templates/routes/_table.html.erb (4.6ms)
Rendered /Users/andreucasadella/.rvm/gems/ruby-2.1.4/gems/actionpack-4.1.7/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (146.0ms)
我也试过将它们移动到:
app/assets/fonts
但还是失败了。
您是否在 config/application.rb
中配置了资产路径以加载 app/assets/fonts
目录?
如果没有,你可以添加这样的内容:
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
完成后,您还应该从 public 已编译资产目录中将字体加载到 sass/less/css/whatever 文件中。例如在 sass 中,您可以使用助手 asset-url
:
@font-face {
font-family: 'MyFont';
src: asset-url('myfont.eot');
src: asset-url('myfont.eot?#iefix') format('embedded-opentype'),
asset-url('myfont.woff2') format('woff2'),
// etc ...
}
您可以在此处详细了解资产的工作原理:http://guides.rubyonrails.org/asset_pipeline.html
我在 public 目录中添加了一个字体文件夹:
public/fonts/glyphicons-halflings-regular.eot
public/fonts/glyphicons-halflings-regular.svg
public/fonts/glyphicons-halflings-regular.ttf
public/fonts/glyphicons-halflings-regular.woff
这解决了问题。