Search code examples
ruby-on-rails-5fixtures

Rails5: fixtures containing json


I need to create a fixture for model Request with following fields: body -> JSON created_at - datetime updated_at - datetime remote_ip - i.e. 127.0.0.01 status - i.e. 1

I've tried:

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

but as a result i do not get o JSON inside body column in db but

---
title: test
Action: test action

What should i do to get full JSON in body field?


Solution

  • the easiest solution i've found is to treat json as a string:

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

    It works, but i am not not sure if it is the best solution....