![](/img/trans.png)
[英]ActionController::InvalidCrossOriginRequest on redirect with GET
[英]ActionController::InvalidCrossOriginRequest in Controller Test
運行像這樣的傳統控制器測試時:
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接受了這一點,但解決方案是使用xhr
方法如下:
xhr :get, :edit, id: object.id
適用於Rails 5+
get :edit, params: { id: object.id }, xhr: true
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.