title: Populate select options in a haml view with JSON data
body: <p>how can I populate <code>%select</code> options in the <code>haml</code> view with <code>JSON</code> parameters I have in <code>sinatra</code> controller.</p>
  
  <p>In the <code>sinatra</code> controller I have:</p>
  
  <pre><code>response = JSON.parse(curl_resp)
  nestedData = response["data"][0]
    nestedData.each do |c|
    names =  c["attributes"]["names"]
  end
  return haml :newPage, :locals =&gt; {:name =&gt; example: name in names}
  </code></pre>
  
  <p>and this the <code>%select</code> options in <code>newPage.haml</code> view:</p>
  
  <pre><code>%select{:name =&gt; "select names"}
    %option{:value =&gt; "id1"} #{locals[:name]}.[0]
    %option{:value =&gt; "id2"} #{locals[:name]}.[1]
    %option{:value =&gt; "id3"} #{locals[:name]}.[2]
    %option{:value =&gt; "id4"} #{locals[:name]}.[3]
  </code></pre>
  
  <p>this is a sample <code>JSON</code> I get from <code>curl</code>:</p>
  
  <pre><code>{"data":[
    {"id":"id1","attributes":{"name":"gnu"}},
    {"id":"id2","attributes":{"name":"Alice"}},
    {"id":"id3","attributes":{"name":"testsubject"}},
    {"id":"id4","attributes":{"name":"testissuer"}}
  ]}
  </code></pre>