我正在创建一个rails应用程序,检查用户是否关注spotify上的艺术家。我用下面的代码来检查是否存在这种情况。
def personalise(acts)
acts_with_rank = acts.collect{|act|{:value => rank(act), :label => act.name}}
end
def rank(act)
spotify_user = RSpotify::User.new(request.env['omniauth.auth'])
artist = RSpotify::Artist.search(act.name).first
binding.remote_pry
if spotify_user.follows?(artist)
10
else
0
end
end
问题是,无论用户是否真正关注艺术家,每个行为最终的哈希值都是10。我使用remote-pry来检查if语句的每次迭代是否返回true或false,尽管它根据用户是否跟随艺术家正确返回true或false,但其他一些东西似乎使if语句返回0。任何帮助将不胜感激,因为我敢肯定,我只是看着这个太长时间,不能看到我所做的愚蠢的事情!
刚刚知道哪里出了问题
spotify_user.follows?(artist)
返回一个布尔值数组,要访问这里感兴趣的布尔值,简单的修复方法是:
if spotify_user.follows?(artist)[0]
10
else
0
end