【问题标题】:Rails5: fixtures containing jsonRails5:包含 json 的固定装置
【发布时间】:2018-12-14 21:47:30
【问题描述】:

我需要使用以下字段为模型请求创建一个夹具: 正文-> JSON created_at - 日期时间 updated_at - 日期时间 remote_ip - 即 127.0.0.01 状态 - 即 1

我试过了:

request1:
  body: {"title": "test", "Action": "test_action"}
  created_at: 2018-06-13 21:15:51
  updated_at: 2018-06-13 21:15:51
  remote_ip: 127.0.0.1
  status: 1

但结果我在 db 的 body 列中没有得到 o JSON,但是

---
title: test
Action: test action

我应该怎么做才能在正文字段中获取完整的 JSON?

【问题讨论】:

    标签: ruby-on-rails-5 fixtures


    【解决方案1】:

    我发现的最简单的解决方案是将 json 视为字符串:

    body: '{"title": "test", "Action": "test_action"}'
    

    它有效,但我不确定它是否是最好的解决方案....

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多