从本地服务器请求javascript时Rails收到CORS错误

时间:2015-08-13 19:00:10

标签: javascript ruby-on-rails cors

我使用head.js为不支持它的浏览器加载对话框polyfill。我在head.js文件中收到了/app/assets/javascripts/application.js,我正试图从/app/assets/javascripts/build/polyfills/dialog-polyfill.js加载polyfill但是我一直收到以下交叉来源错误

ActionController::InvalidCrossOriginRequest in BaseController#index
Security warning: an embedded <script> tag on another site requested protected JavaScript. If you know what you're doing, go ahead and disable forgery protection on this action to permit cross-origin JavaScript embedding.

Rails.root: /Users/rich/IdeaProjects/test_project

Application Trace | Framework Trace | Full Trace
Request

Parameters:

{"path"=>"assets/javascripts/build/polyfills/dialog-polyfill.min","format"=>"js"}

会话转储

_csrf_token: "phRgTk+ckBBhFegpIu+mwvkIJzd57rt4T6XZUE8Wee4="
session_id: "7f5e825832ba66bdc94ea27ab930d04c"

环保转储

GATEWAY_INTERFACE: "CGI/1.1"
HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
HTTP_ACCEPT_ENCODING: "gzip, deflate"
HTTP_ACCEPT_LANGUAGE: "en-us"
REMOTE_ADDR: "127.0.0.1"
REMOTE_HOST: "127.0.0.1"
SERVER_NAME: "localhost"
SERVER_PROTOCOL: "HTTP/1.1"

1 个答案:

答案 0 :(得分:0)

你是不是正在使用

将build / polyfills / *拉入你的application.js清单中

// = require_tree。

?我的理解是渲染单个大型CSS文件比获取多个文件更快。有关清单文件here的更多信息。