Ruby on Rails 使用 OPTION 而不是 GET 进行重定向

问题描述 投票:0回答:1

我的代码使用选项请求而不是 get 进行重定向,这可能是什么原因造成的?

重定向来自这里:

  def destroy
    sign_out
    redirect_to "#{YAML.load_file("#{Rails.root}/config/sso.yml")[Rails.env]["provider_url"]}/logout?redirect=#{root_url}", allow_other_host: true
  end

在另一个应用程序上返回此错误:

为 ::1 启动选项“/logout?redirect=http://localhost:3009/” 2024-09-18 15:16:29 -0300 ActionController::RoutingError(无路由 匹配[选项]“/注销”):

Rails 7.0.8.4 红宝石 2.7.8p225

ruby-on-rails ruby rubygems
1个回答
0
投票

正如我在我的评论中所写,这是 CORS 的问题。

这篇文章这样的内容应该可以帮助您配置 Rails 应用程序以适当地响应 OPTIONS 请求。您可以安装rack-cors gem 并添加一个初始化程序,告诉您的应用程序应该接受来自哪个域的请求:

Rails.application.config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins 'http://example.com:80'
    resource '*', headers: :any, methods: [:get, :post]
  end
end
© www.soinside.com 2019 - 2024. All rights reserved.