Tom*_*ssi 30 ruby-on-rails ruby-on-rails-4.1
运行像这样的传统控制器测试时:
get :edit, id: object.id, format: :js
Run Code Online (Sandbox Code Playgroud)
我的测试在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.
Run Code Online (Sandbox Code Playgroud)
Tom*_*ssi 38
较旧版本的Rails接受了这个,但解决方案是使用xhr
如下方法:
xhr :get, :edit, id: object.id
Run Code Online (Sandbox Code Playgroud)
Joh*_*ard 34
适用于Rails 5+
get :edit, params: { id: object.id }, xhr: true
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6225 次 |
最近记录: |