在运行这样的旧式 Controller 测试时:
get :edit, id: object.id, format: :js
我的测试在Rails 4.1中开始失败,并出现以下错误:
ActionController::InvalidCrossOriginRequest: 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 5+
get :edit, params: { id: object.id }, xhr: true
关于ruby-on-rails - Controller 测试中的ActionController::InvalidCrossOriginRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24918994/