Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Jeremy Frimond
Jeremy Frimond
14,470 Points

ROR Each Loop Display odd index key entries only

I am working with a dataset which I would like only for the odd number index key entries to be displayed with my each loop in the view file. Right now it works and I get everything.

Here is my controller.rb:

  def index
#Wunderground Controller for API Requests
@wundergroundMap = HTTParty.get('http://api.wunderground.com/api/MySecretAPIKey/satellite/q/CA/Laguna_Beach.json')
@wuMultiDay = @wundergroundForecast['forecast']['txt_forecast']['forecastday']
  end

Here is my view file and loop:

 <% @wuMultiDay.each do |wu| %>
    <div style="width:200px; height: 400px; float: left; border:1px solid; display:inline-block;">


        <h6> Period <%= wu['period'] %></h6>
        <h3 style="text-align:center;"> <%= wu['title'] %></h3>
        <p style="text-align:justify;"><strong>Conditions:</strong><br> <%= wu['fcttext'] %></p>


    </div>
<% end %>

Thanks!