AbNadi
AbNadi

Reputation: 69

undefined method `each' for #<SoundCloud::Client:0x87288f0>

I hope someone can help, i can connect to soundcloud and get a list of items but it is just a bunch of text. when i try to order it in a list a get the error "undefined method `each' for #SoundCloud::Client:0x87288f0>"

soundcloud controller:

def self.search
  @client = Soundcloud.new(:client_id => ENV["SOUNDCLOUD_CLIENT_ID"])
end

search.html.erb

<!--this works-->
<%= @client.get('/tracks', :q => 'some user') %>

<!--this does not-->
<% @client.each do |s| %>
    <ul>
        <li><%= s.get('/tracks', :q => 'some user') %></li>
    </ul>
<% end %>

Upvotes: 0

Views: 30

Answers (1)

Nic Nilov
Nic Nilov

Reputation: 5155

Try this:

<% @client.get('/tracks', :q => 'some user').each do |track| %>
    <ul>
        <li><%= track.title %></li>
    </ul>
<% end %>

@client.get('/tracks', :q => 'some user') returns a collection of track objects which can be enumerated.

By themselves track objects are not enumerable and that is why you are getting error when trying to call .each method on one of them.

Upvotes: 1

Related Questions