Ruby on rails 既然Rails 5.1不支持'xhr'和'xml_http_请求',如何配置和测试外部JS请求?
我正在测试一个控制器动作,该动作响应可嵌入外部站点的脚本Ruby on rails 既然Rails 5.1不支持'xhr'和'xml_http_请求',如何配置和测试外部JS请求?,ruby-on-rails,Ruby On Rails,我正在测试一个控制器动作,该动作响应可嵌入外部站点的脚本 xhr :get, :index, params: { format: :js } Rails已开始引发以下注意事项 DEPRECATION WARNING: `xhr` and `xml_http_request` are deprecated and will be removed in Rails 5.1. Switch to e.g. `post :create, params: { comment: { body: 'Hone
xhr :get, :index, params: { format: :js }
Rails已开始引发以下注意事项
DEPRECATION WARNING: `xhr` and `xml_http_request` are deprecated and will be removed in Rails 5.1.
Switch to e.g. `post :create, params: { comment: { body: 'Honey bunny' } }, xhr: true`.
如果我按照这些建议修改控制器规范
get :index, params: { format: :js }, xhr: true
我得到以下错误
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.
如果是这样,那么前面的xhr:get
语法是如何启用请求以避免跨源错误的
# my_embeddable_controller.rb
protect_from_forgery except: :index