Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


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']

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>

<% end %>