我在 生产环境 的服务器上有一个api,我安装了cors rack以允许我的gemfile中的ajax调用我把gem'rack-cors'和我使用了bundle install . 之后,我将以下代码放在config / application.rb中:

require File.expand_path('../boot', __FILE__)

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module XXX
  class Application < Rails::Application

    config.autoload_paths += %W(#{config.root}/app/models/ckeditor)

    config.to_prepare do
      Devise::SessionsController.layout false
      Devise::RegistrationsController.layout "application"
      Devise::ConfirmationsController.layout false
      Devise::UnlocksController.layout false
      Devise::PasswordsController.layout false
    end
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de


    config.action_mailer.delivery_method = :smtp

      config.action_mailer.raise_delivery_errors = false

      config.middleware.insert_before 0, "Rack::Cors" do
      allow do
        origins '*'
        resource '*', :headers => :any, :methods => [:get, :post, :put, :patch, :delete, :options]
      end
  end

  end
end

我在 生产环境 中上传了我的代码并在那里安装了bundle来安装gem . 当我从https://resttesttest.com/获取 endpoints 数据时,我得到:

哦不! Javascript返回HTTP 0错误 . 可能发生这种情况的一个常见原因是您从服务器请求了跨域资源,该服务器在响应中未包含相应的CORS头 . 更好地打开你的Firebug ......

有人可以帮忙吗?