Ruby on rails “如何修复”;没有将字符串隐式转换为哈希;

Ruby on rails “如何修复”;没有将字符串隐式转换为哈希;,ruby-on-rails,ruby,http,Ruby On Rails,Ruby,Http,我尝试使用RSpec运行测试,但它总是返回相同的错误: DevicesController#update when user is a manager must update any device Failure/Error: put device_path device_id, params: params, headers: { 'Content-Type': 'application/vnd.api+json' } TypeError: no impli

我尝试使用RSpec运行测试,但它总是返回相同的错误:

DevicesController#update when user is a manager must update any device
     Failure/Error: put device_path device_id, params: params, headers: { 'Content-Type': 'application/vnd.api+json' }

     TypeError:
       no implicit conversion of String into Hash
具有请求参数的My函数:

def update_params(device, device_id)
  {
    data: {
      id: device.id,
      type: 'device',
      attributes: {
        device_id: device_id 
      }
    }
  }.to_json
end
我使用工厂进行的测试:

context 'when user is a manager' do
  let(:user) { create(:manager).account }
  let(:firebase_token) { Faker::Crypto.sha1 }
  let(:device_id) { physical_device.id }
  let(:params) { update_params(physical_device, firebase_token) }
  it 'must update any device' do
    expect(Device.find(device_id).device_id).to eq(firebase_token)
  end
end
请求操作系统更新设备:

put device_path device_id, params: params, headers: { 'Content-Type': 'application/vnd.api+json' }
期望
参数
是散列(如
标题

但是传递给此方法调用的
params

put device_path device_id, params: params, headers: { 'Content-Type': 'application/vnd.api+json' }
update_params
方法生成,该方法在生成的哈希上调用
到_json
,因此返回一个json字符串


只需从
更新参数
方法的最后一行删除
.to_json
,您就可以了。

尝试将
设备id
包装在
设备路径
方法(
设备路径(设备id)
)中。删除更新参数中的“.to_json”。这将参数散列转换为jsonI的字符串,使用与to_json相同的主体请求来创建方法,并出现此错误dnt ocurred,dsnt make senseYeah,我尝试使用put(device_path(device_id)…),但服务器返回我400-错误请求很好。这意味着您的测试请求有效!问题解决了。但不幸的是,您的应用程序无法处理
应用程序/vnd.api+json
mime类型。您是否在Rails应用程序中注册了该mime类型?例如,通过以下方式?因为这实际上是一个不同的问题,如果链接不能解决这个问题,你可能会想打开一个新的问题。