Question

I have this method in my Artist model

def upcomingEvents

        @remote = Songkickr::Remote.new 'asdf123asdf'
        id = @remote.artist_search(:name).results.first.id
        artistConcerts = @remote.artist_events(id, :per_page => '10').results

        return artistConcerts
end

Which should return 10 results from the API call I make.

Then in my view I'm trying to do a .each call to iterate through the 10 returns objects.

<% @concert.artist.upcomingEvents.each do |event| %>
  <p><%= link_to event.display_name + " " + event.location.city, event.uri, :target => "_blank"%></p>
<% end %>

the .display_name and .city and .uri methods are built into the gem I'm using that's an API wrapper. When I try to do this nothing gets printed though so I just wanted to make sure what I was trying to do is possible, and if not, how can I do it?

Was it helpful?

Solution

Yes you call each on an array. If you have any doubts you can simply check the ruby (or rails) doc: http://www.ruby-doc.org/core-2.1.1/Array.html

P.s. I would write tests for every step if I were you. This way you can see if every part is returning the right result. Without tests you could use binding.pry to check for unexpected outcomes. In your case I wonder if @concert.artist.upcomingEvents returns anything but an empty array.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top