【发布时间】:2015-10-27 06:05:16
【问题描述】:
在我的 rails 应用程序中,其中一个控制器显示了我希望托管在不同域上的网站从中提取数据的公共统计信息。 (app.donornest.com/stats.json)
我的控制器代码如下:
class StatsController < ApplicationController
require 'ostruct'
skip_before_action :verify_authenticity_token
respond_to :html, :xml, :json, :csv
def index
@stats = OpenStruct.new
@stats.users = User.all.count
@stats.organizations = Organization.all.count
@stats.donors = Person.all.count
respond_to do |format|
format.json {render json: @stats}
end
end
end
我认为 skip_before_action :verify_authenticity_token 行就足够了,但是当我尝试从控制台向该页面发出请求时,我收到以下错误:
XMLHttpRequest cannot load http://app.donornest.com/stats.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
我该如何解决这个问题?
【问题讨论】:
标签: ruby-on-rails csrf