我编译我的资产没有错误,他们在开发环境中工作没有问题,但他们都在生产中破产。我检查了我的日志文件,似乎它没有引用正确的位置。这是错误之一。
INFO -- : Started GET "/homeFoods/fonts/glyphicons-halflings-regular.woff2" for 132.241.174.123
at 2016-04-08 22:35:59 +0000 F, [2016-04-08T22:35:59.294695 #26882] FATAL -- :
ActionController::RoutingError (No route matches [GET] "/fonts/glyphicons-halflings-regular.woff2"):
actionpack (4.2.5) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.5) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.5) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.5) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.5) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.5) lib/rails/engine.rb:518:in `call'
railties (4.2.5) lib/rails/application.rb:165:in `call'
passenger (5.0.24) src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request'
passenger (5.0.24)
src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:152:in `accept_and_process_next_request' passenger(5.0.24)src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:113:in `main_loop'passenger(5.0.24) src/ruby_supportlib/phusion_passenger/request_handler.rb:416:in `block (3 levels) in start_threads' passenger(5.0.24) src/ruby_supportlib/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'
为什么假设字体目录位于homeFoods下而不是/ homeFoods / app / assets /?
application.rb
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
config.assets.precompile += %w( .svg .eot .woff .ttf )
bootstrap.css
font-face {
font-family: 'Glyphicons Halflings';
src: url('/assets/glyphicons-halflings-regular.eot');
src: url('/assets/glyphicons-halflings-regular.eot?#iefix')
format('embedded-opentype'), url('/assets/glyphicons-halflings-regular.woff') format('woff'), url('/assets/glyphicons-halflings-regular.ttf') format('truetype'), url('/assets/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');}
我确实尝试了这种方法Bootstrap 3+Rails 4 - Certain Glyphicons not working以前工作但不再工作。我不知道它为什么工作,因为他指定的路径不正确,供应商不包含字体文件夹。
config.assets.paths << "#{Rails}/vendor/assets/fonts"
答案 0 :(得分:0)
在这种情况下,我只需创建一个新文件icons.css.scss
并在其中使用asset-url
帮助器。例如:
@font-face {
font-family: 'EntypoRegular';
src: asset-url('fontello.eot');
src: asset-url('fontello.eot?#iefix') format('embedded-opentype'),
asset-url('fontello.ttf') format('truetype'),
asset-url('fontello.woff') format('woff'),
asset-url('fontello.svg#EntypoRegular') format('svg');
}
接下来,我通过添加application.css.scss
在我的//= require icons
中添加此文件。希望这有帮助。