【问题标题】:Specify the correct path in assets pipeline Rails 4+在资产管道中指定正确的路径 Rails 4+
【发布时间】:2016-07-30 08:49:09
【问题描述】:

我编译我的资产没有错误,它们在开发环境中工作没有问题,但它们都在生产中中断。我检查了我的日志文件,它似乎没有引用正确的位置。这是错误之一。

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

应用程序.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"

【问题讨论】:

  • 有助于在页面加载时查看控制台错误。
  • 我提到的错误就是问题所在。加载页面时它不显示我的图标!
  • 祝你好运。

标签: twitter-bootstrap ruby-on-rails-4


【解决方案1】:

在这种情况下,我只需创建一个新文件 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'); }

接下来我通过添加//= require icons 将此文件包含在我的application.css.scss 中。希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2016-08-15
    • 2014-07-04
    • 2014-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多