滑轨。请求的资源上不存在“ Access-Control-Allow-Origin”标头

时间:2018-07-13 10:51:33

标签: ruby-on-rails angular

错误:所请求的资源上没有“ Access-Control-Allow-Origin”标头。

Backund Ruby on Rails,前端为Angular 5。

application.rb

...
module Dkeeper
  class Application < Rails::Application
    config.middleware.use Rack::Cors do
      allow do
      origins '*'
      resource '*', headers: :any, methods: [:get, :post, :put, :patch, :delete, :options, :head]
    end
end
...

1 个答案:

答案 0 :(得分:1)

根据docs

,您好像丢失了insert_before 0。
config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins '*'
    resource '*', headers: :any, methods: [:get, :post, :options]
  end
end