title: Implementing Soundcloud Player with Rails SDK
body: <p>I´m a newbie rails developer, I´m trying to do a simple thing with rails and soundcloud but seems that after some days messing around with the API documentation can´t find the best way to do what I want.</p>
  
  <p>Im trying to develop a contest for a local pub where DJ´s can send us their best track and they are voted to win a prize.</p>
  
  <p>My approximation to this is storing the soundcloud url of his track in a database field and then this tracks are showed in the web through the little soundcloud player.</p>
  
  <p>I think I can use this code in the view file.</p>
  
  <pre><code>&lt;div id="player"&gt;
  &lt;object height="70" width="100%"&gt;
    &lt;param name="movie" value="https://player.soundcloud.com/player.swf?    url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F{"&lt;%= @trackid %&gt;"}&amp;player_type=tiny{widgetParams}"&gt;    &lt;/param&gt;
    &lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;
    &lt;param name="wmode" value="transparent"&gt;&lt;/param&gt;
    &lt;embed wmode="transparent" allowscriptaccess="always" height="18" width="100%"     src="https://player.soundcloud.com/player.swf?    url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F{trackId}&amp;player_type=tiny{widgetParams}"&gt;    &lt;/embed&gt;
  &lt;/object&gt; 
  &lt;/div&gt;
  </code></pre>
  
  <p>To change the {trackid} im using the value of the track.id, which i get in the controller with this code</p>
  
  <pre><code> client = Soundcloud.new(:client_id =&gt; '2074955755d1c3997e10463d8a56960f')
  
  # call the resolve endpoint with a track url
  track = client.get('/resolve', :url =&gt; "http://soundcloud.com/forss/flickermood")
  
  # print the track id
  @trackid = track.id
  </code></pre>
  
  <p>This is not working.</p>
  
  <p>Another way I tried to make this work is trough the oEmbed. I tried to run the example in the API documentation.</p>
  
  <p>In the View file I understand I have to put the Javascript Widget:</p>
  
  <pre><code>&lt;script src="http://connect.soundcloud.com/sdk.js"&gt;&lt;/script&gt;
  &lt;script&gt;
  SC.initialize({
    client_id: 'xxxxxxxxxxxxxxxxxxxxxxx'
  });
  
  var track_url = 'http://soundcloud.com/forss/flickermood';
  SC.oEmbed(track_url, { auto_play: true }, function(oEmbed) {
    console.log('oEmbed response: ' + oEmbed);
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>And in the controller this code:</p>
  
  <pre><code># create a client object with your app credentials
  client = Soundcloud.new(:client_id =&gt; 'xxxxxxxxxxxxxxxxxxxx')
  
  # get a tracks oembed data
  track_url = 'http://soundcloud.com/forss/flickermood'
  embed_info = client.get('/oembed', :url =&gt; track_url)
  
  # print the html for the player widget
  puts embed_info['html']
  </code></pre>
  
  <p>I´m a bit lost and I think im failing in some basic thing, and thats why I dont find info about how exactly implement this.</p>
  
  <p>Thanks for your time</p>