title: Rails - Saving external API call to DB
body: <p>I'm making a GET call to an external source (a Spree Commerce store) for getting the list of orders... the call is working fine but I need to save the order list to my rails app's db. I have no idea how to do this.</p>
  
  <p>My Controller:</p>
  
  <pre><code>def index
    # GRAB THE URL
    url = 'https://cuytest1.herokuapp.com/api/v1/orders.json?token=982fe19b763ee46bf1ea6ca6ddf70c61f2b6571c7434c22c'
    response = HTTParty.get(url)
  
    # PARSE THE RESPONSE
    @orders = response.parsed_response["orders"]
  end
  </code></pre>
  
  <p>My model:</p>
  
  <pre><code>class Order &lt; ApplicationRecord
    include HTTParty
  end
  </code></pre>
  
  <p>My view:</p>
  
  <pre><code>&lt;p id="notice"&gt;&lt;%= notice %&gt;&lt;/p&gt;
  
  &lt;h1&gt;Orders&lt;/h1&gt;
  
  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;Number&lt;/th&gt;
        &lt;th&gt;Total&lt;/th&gt;
        &lt;th&gt;State&lt;/th&gt;
        &lt;th colspan="3"&gt;&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
  
    &lt;tbody&gt;
      &lt;% @orders.each do |order| %&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;%= order["number"] %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= order["total"] %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= order["shipment_state"] %&gt;&lt;/td&gt;
  
        &lt;/tr&gt;
      &lt;% end %&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>If anyone can point me into the right direction will be appreciated. Thanks a lot!</p>