没有访问控制允许来自rails

时间:2018-01-28 13:12:37

标签: javascript ruby-on-rails cors httprequest

我正在尝试使用Ruby on rails在rails应用程序中使用Heroku部署的api时遇到此错误:

 Failed to load https://**: my API link deployed on Heroku No 
'Access-Control-Allow-Origin' header is present on the requested resource.
 Origin 'http://localhost:3000' is therefore not allowed access.

1 个答案:

答案 0 :(得分:1)

不允许通过CORS

http://localhost:3000。您需要在heroku上部署的rails应用程序中进行设置。

将以下代码段添加到config/application.rb文件中,然后重新部署到heroku

  config.middleware.insert_before 0, Rack::Cors do
    allow do
      origins 'http://localhost:3000'
      resource '*', :headers => :any, :methods => [:get, :post, :options]
    end
  end