I'm fairly new at integrating APIs in Ruby on Rails but I want to use Soundcloud's API to embed a player widget when provided a Soundcloud URL from a user. Right now I have the widgets embedded in my table through a test link. Each post contains string called link but I don't know how to reference it inside the controller. Or would I point to link in my view? Here's what I have so far. Any help would be appreciated.
class PostsController < ApplicationController
require 'soundcloud'
def index
@client = Soundcloud.new(:client_id => 'xxxxx')
@posts = Post.search(params[:search]).order(sort_column + " " + sort_direction)
track = @client.get('/resolve', :url => post.link )
@trackid = track.id
end
private
def set_post
@post = Post.find(params[:id])
end
def post_params
params.require(:post).permit(:link)
end
end
Here's the corresponding view.
<% provide(:title, 'Home') %>
<table>
<thead>
<tr>
<th>Link</th>
</tr>
</thead>
<tbody>
<% @posts.each do |post| %>
<td><div id="player"><object height="70" width="100%"><param name="movie" value="http://ift.tt/1ECyM9F @trackid %>&player_type=tiny{widgetParams}"></param>
<param name="allowscriptaccess" value="always"></param>
<param name="wmode" value="transparent"></param>
<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}&player_type=tiny{widgetParams}"> </embed></object></div></td>
<% end %>
</tbody>
Aucun commentaire:
Enregistrer un commentaire