我在 gemfile 中有它gem 'rack-cors', require: 'rack/cors'。我做了捆绑安装。
我还在 config/initializers/cors.rb 中进行了设置
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*',
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
end
Run Code Online (Sandbox Code Playgroud)
之后我确实重新启动了服务器。
这是我得到的错误:
Access to XMLHttpRequest at 'localhost:3000/articles' from origin 'http://localhost:8080' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
Run Code Online (Sandbox Code Playgroud)
这是我的仓库Portfolio_App。