Rails 反应管理 | Access-Control-Expose-Headers X-Total-Count 错误

问题描述

我已将 react-admin 连接到我的 Rails API,但出现此错误

The X-Total-Count header is missing in the HTTP Response. The jsonServer Data Provider expects responses for lists of resources to contain this header with the total number of results to build the pagination. If you are using CORS,did you declare X-Total-Count in the Access-Control-Expose-Headers header?

我已尝试对我的 ApplicationController.rb 进行以下更改

class ApplicationController < ActionController::API
  after_action :custom_headers

  def custom_headers
    response.set_header['Access-Control-Expose-Headers'] = 'X-Total-Count'
  end
end

虽然这不再给我以前的错误,但由于参数数量错误(预期为 2,收到 0),我现在收到内部服务器错误。我是否遗漏了一个步骤,或者是否有不同的方式将我的 API 连接到 react-admin

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)