Spotify APIのgemであるRSpotifyを使って、アーティスト名を検索し、検索結果を表示させるものを実装しています。
以下のindex.html.erbの、<%=artist.name%>と同様にしてアーティストの画像も取得したいです。
どのように画像を表示すればいいでしょうか??
musics_controller
1class MusicsController < ApplicationController 2 require 'rspotify' 3 RSpotify.authenticate(" ", " ") 4 5 def search 6 end 7 8 def index 9 @artists = RSpotify::Artist.search(params[:search]) 10 end 11end
search
1<h3>アーティスト名で検索</h3> 2 3 <%= form_tag(controller:"musics",action:"index") do %> 4 <%= text_field_tag :search %> 5 <%= submit_tag 'Search',:name => nil %> 6 <% end %> 7
index
1<% @artists.each do |artist| %> 2 <h4><%= artist.name %></h4> 3<% end %>
ちなみに、<%=arsiti.images%>で表示してみると、以下のようになります。
これのurlを取得してimage_tagに引数として与えたいです。
[{"height"=>640, "url"=>"https://i.scdn.co/image/2a8c10fe954e2038fb74251cba601a5594cc5878", "width"=>640}, {"height"=>320, "url"=>"https://i.scdn.co/image/87d18c79bbfdb1905bb202d200e1c191afc46aa5", "width"=>320}, {"height"=>160, "url"=>"https://i.scdn.co/image/b4d024ebb4863438b92a1b029bff7f9737263a57", "width"=>160}] [{"height"=>640, "url"=>"https://i.scdn.co/image/91330ce6df5635ffcf65f2d1e312f7585af6e2e4", "width"=>640}, {"height"=>300, "url"=>"https://i.scdn.co/image/717b5440157eeef9c7e910621e1754bc10b0a565", "width"=>300}, {"height"=>64, "url"=>"https://i.scdn.co/image/9dbc4d36937d01388ad522f3c3b7c1414089608e", "width"=>64}] [{"height"=>640, "url"=>"https://i.scdn.co/image/60707b57e4f50c3506042528692f0d85f0f3a0c3", "width"=>640}, {"height"=>300, "url"=>"https://i.scdn.co/image/09ba248ec74bad1922095a11898f4cb2afebb226", "width"=>300}, {"height"=>64, "url"=>"https://i.scdn.co/image/cea55dfa69bda3eccf4d4163c2c1ffb93cead5d8", "width"=>64}] [{"height"=>640, "url"=>"https://i.scdn.co/image/429bc8d84d6a41845a12946949b25e18a2ced4fd", "width"=>640}, {"height"=>300, "url"=>"https://i.scdn.co/image/babfb7cae54da34810119c5c1d92206bf32beb20", "width"=>300}, {"height"=>64, "url"=>"https://i.scdn.co/image/d7773b4c677f9ee5f9ec4e56c725a50fce47af33", "width"=>64}]
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。