使用Rspotify时,在控制台与应用程序中获得不同的响应

时间:2017-05-10 06:31:00

标签: ruby-on-rails api rubygems

我正在尝试使用Rspotify gem(它是Spotify API的包装器)对艺术家进行简单搜索 - 基本上类似于概述in this blog post

问题是当我在我的控制台中运行搜索而不是通过UI在我的应用程序中运行时,我得到了不同的响应。我应该在UI上获取完整的数据集,就像我在控制台中一样。

这是我的表单摘录:

<%= form_for :artist, url: artist_search_path, html: {class: "form-inline"} do |f| %>
  <div class="form-group">
    <%= f.text_field :artist_name, class: "form-control", placeholder: "Enter artist or group" %>
    <%= f.submit "Search", class: "btn btn-success" %>
  </div>
<% end %>

两条路线:

get 'profile', to: "pages#profile"
post 'artist_search', to: "artists#search"

这是我的艺术家控制器代码段:

def search
  if !params[:artist][:artist_name].blank?
    @artists = RSpotify::Artist.search(params[:artist][:artist_name])
    redirect_to profile_path
  end
end

以下是我在用户界面上提交艺术家姓名并在我的日志中打印@artists时获得的内容摘要:

Processing by ArtistsController#search as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"uzubTTE/bZvLBbU0MpY8lmLur1YPExnwdvXMXs882D7bm+fcUgTC8zRLizPh9Gp7eUjG2cGkNIGSk/Z+aZhrpg==", "artist"=>{"artist_name"=>"Drake"}, "commit"=>"Search"}
#<RSpotify::Artist:0x007faf454f4f60>
#<RSpotify::Artist:0x007faf454f4f10>
#<RSpotify::Artist:0x007faf454f4ec0>
# Bunch more of the above...
Redirected to https://website.com/profile
Completed 302 Found in 81ms (ActiveRecord: 0.0ms)

当我在控制台中运行搜索时,我得到了这些列表:

[#<RSpotify::Artist:0x000000049f0bd8 @followers={"href"=>nil, "total"=>2645122}, @genres=["east coast hip hop", "hip hop", "pop rap", "rap", "southern hip hop", "trap music"], @images=[{"height"=>667, "url"=>"https://i.scdn.co/image/f58a98bc92cd2dc7020fc45a45eebb29380048ab", "width"=>1000}, {"height"=>427, "url"=>"https://i.scdn.co/image/9dd1bab34761764a125508534e443a9b245a9b56", "width"=>640}, {"height"=>133, "url"=>"https://i.scdn.co/image/620b2133ab3f20045c0d9669e706bbf11786cf78", "width"=>200}, {"height"=>43, "url"=>"https://i.scdn.co/image/5018ebe8a0d1060e6b39b2021132c082be1a913d", "width"=>64}], @name="JAY Z", @popularity=83, @top_tracks={}, @external_urls={"spotify"=>"https://open.spotify.com/artist/3nFkdlSjzX9mRTtwJOzDYB"}, @href="https://api.spotify.com/v1/artists/3nFkdlSjzX9mRTtwJOzDYB", @id="3nFkdlSjzX9mRTtwJOzDYB", @type="artist", @uri="spotify:artist:3nFkdlSjzX9mRTtwJOzDYB">]

0 个答案:

没有答案