Convert json to hash to insert with Active Record
<p>I'm still practising processing arrays and hashes, and particularly getting to details in 2d or 3d structures. I'm trying to use details in a json file to process some data ready to insert into the db with Active Record. </p>

<p>Here is my json structure for 'my_file.json'</p>

<pre><code># my_file.json    

[
  {
    "name": "Joe Bloggs",
    "telephone": "012-345-6789"
  },
  {
    "name": "Hilda Bloggs",
    "telephone": "012-345-6789"
  }
]
</code></pre>

<p>and here is the code I'm using to convert the json data into something I can insert into my db</p>

<pre><code>   def json_insert_to_db
      require 'json'
      file = File.read('my_file.json')
      json_data = JSON.parse(file)
      details = json_data.map do |x|
        user = User.new
        user.name = json_data[x]['name']
        user.telephone = json_data[x]['telephone']
      end
    end
</code></pre>

<p>With this I get </p>

<pre><code>NameError: uninitialized constant User
</code></pre>

<p>(User does exist in the database, by the way) </p>

<p>I can't work out where I'm going wrong, but I know it's something simple I am overlooking. Thanks for any help.</p>