title: Rewrite JSON structure and include an EACH loop in Rails
body: <p>I have a list of shows in a database that need to be output in a certain JSON style in order to work with Polymaps.</p>
  
  <p>Part of this includes the need to iterate over one section in order to create a list of points. I'm pretty certain that this needs to be achieved using :include in the render :json => @results bit of the code.</p>
  
  <p>Here's the code as it stands:</p>
  
  <pre><code>def gigs
  
    @gigs = Show.where(:displayname =&gt; "Vans Warped Tour 2011")
  
    @giggage = [{
    :type =&gt; "FeatureCollection",
    :features =&gt; [
      @gigs.each do |gig|
        :type =&gt; "feature",
        :geometry =&gt; {
          :coordinates =&gt; [
            gig['lng'], 
            gig['lat']
          ],
         :type =&gt; "Point"
        },
        :properties =&gt; gig
      end
      ]
    }]
  
    render :json =&gt; @giggage
  end
  </code></pre>
  
  <p>There's an each loop inside a hash which I know you can't do, but that's the best way to illustrate what I'm going for, I'm going in circles on this.</p>
  
  <p>I did try this which got me some of the way there, but only returned the one result because of the structure of the loop:</p>
  
  <pre><code>def gigs
    @gigs = Show.where(:displayname =&gt; "Vans Warped Tour 2011")
    @gigs.each do |gig|
      @gigs_to_render = {
        :type =&gt; "FeatureCollection",
        :features =&gt; [
            :type =&gt; "feature",
            :geometry =&gt; {
              :coordinates =&gt; [
                gig['lng'], 
                gig['lat']
              ],
             :type =&gt; "Point"
            },
            :properties =&gt; gig
       ]
      } 
  end
  render :json =&gt; @gigs_to_render
  </code></pre>
  
  <p>end</p>
  
  <p>Thanks for your help! Anyone. Everyone!</p>