Ruby on rails 访问字体“;字体url";“来源于原产地”;Url";已阻止CORS错误
你好,我仔细看了一下,找不到答案 错误很明显,但解决方案却不是这样 未加载自定义字体。我在Ruby on rails 访问字体“;字体url";“来源于原产地”;Url";已阻止CORS错误,ruby-on-rails,cors,Ruby On Rails,Cors,你好,我仔细看了一下,找不到答案 错误很明显,但解决方案却不是这样 未加载自定义字体。我在assets/fonts/TypoGraphica.eot 以下是错误: font.scss @font-face { font-family:"TypoGraphica"; src: font-url("TypoGraphica.eot?") format("eot"), font-url("TypoGraphica.woff") format("woff"),
assets/fonts/TypoGraphica.eot
以下是错误:
font.scss
@font-face {
font-family:"TypoGraphica";
src: font-url("TypoGraphica.eot?") format("eot"),
font-url("TypoGraphica.woff") format("woff"),
font-url("TypoGraphica.ttf") format("truetype"),
font-url("TypoGraphica.svg#TypoGraphica") format("svg");
}
.typographica { font-family: $font-typographica; }
这是我的cors。目前,我允许任何请求:
module Taddar
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Do not swallow errors in after_commit/after_rollback callbacks.
config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*', headers: :any, methods: [:get, :post, :options]
end
end
config.active_job.queue_adapter = :delayed_job
config.browserify_rails.commandline_options =
'-t [ babelify --presets [ env react stage-0 ] --plugins [ syntax-async-functions transform-regenerator ] ]'
end
end
模块Taddar
类应用程序
有人知道我做错了什么吗?来自另一个来源
对于我的同病相怜者,以下是我最终如何解决这个问题的。问题不在于gem本身,问题在于堆栈没有提供选项路由,就像ruby之外的任何其他框架一样(wth?),如果您习惯于使用Java或类似的东西,这可能会让您措手不及
因此,在routes.rb中添加这些路由可以解决问题:
# global options responder -> makes sure OPTION request for CORS endpoints work
match '*path', via: [:options], to: lambda {|_| [204, { 'Content-Type' => 'text/plain' }]}
通过将以下内容添加到
assets.rb
Rails.application.config.assets.precompile