在控制器中解析 SoundCloud 轨道

Resolve SoundCloud track in controller

首先,我对 Rails 上的 Ruby 和 SoundCloud API 很陌生,如果这是一个愚蠢的问题,我深表歉意。

我的问题是,我正在尝试使用 SoundCloud 解析曲目功能来获取有关 post 的曲目信息。

现在我设置了一个脚手架,它使用

遍历每个 post
<% @posts.each do |post| %> 
    <%= post.soundcloud %>
<% end %>

.soundcloud就是我要解析的歌曲的url。

我试过了

<%= @client.get('/resolve', :url => <%= post.soundcloud %> ) %>

但后来意识到我不能嵌套 erb 标签。

我也试过在控制器中传递各种方法,但我似乎无法弄明白。

哦,这是我的控制器的样子。

def index
   require 'soundcloud'
   @posts = Post.all
   @client = Soundcloud.new(:client_id => 'MY_CLIENT_ID')
   @tracks = @client.get('/resolve', :url => '') <-- Don't know what to do with this
end

有什么建议吗?

提前致谢

我没有检查文档,但从你的代码来看,你的 erb 文件应该是

  <% @posts.each do |post| %> 
     <%= @client.get('/resolve', url: post.soundcloud ) %>
  <% end %>