質問編集履歴

2

ソースコードの変更

2019/04/28 15:38

投稿

Kassy11
Kassy11

スコア26

test CHANGED
File without changes
test CHANGED
@@ -59,3 +59,21 @@
59
59
  <% end %>
60
60
 
61
61
  ```
62
+
63
+
64
+
65
+ ちなみに、<%=arsiti.images%>で表示してみると、以下のようになります。
66
+
67
+ これのurlを取得してimage_tagに引数として与えたいです。
68
+
69
+ ```
70
+
71
+ [{"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}]
72
+
73
+ [{"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}]
74
+
75
+ [{"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}]
76
+
77
+ [{"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}]
78
+
79
+ ```

1

ソースコードの記載

2019/04/28 15:38

投稿

Kassy11
Kassy11

スコア26

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
- Spotify APIを使って、アーティスト名を検索し、検索結果を表示させるものを実装しています。
1
+ Spotify APIのgemであるRSpotifyを使って、アーティスト名を検索し、検索結果を表示させるものを実装しています。
2
2
 
3
- 以下のように、<%=artist.images%>で表示されているurlを取得して画像て表示させたいと考えています。
3
+ 以下のindex.html.erbの、<%=artist.name%>と同様にしてアーティストの画像も取得したいす。
4
4
 
5
5
  どのように画像を表示すればいいでしょうか??
6
6
 
@@ -8,28 +8,54 @@
8
8
 
9
9
  ```musics_controller
10
10
 
11
+ class MusicsController < ApplicationController
12
+
13
+ require 'rspotify'
14
+
15
+ RSpotify.authenticate(" ", " ")
16
+
17
+
18
+
19
+ def search
20
+
21
+ end
22
+
23
+
24
+
11
- def index
25
+ def index
12
26
 
13
27
  @artists = RSpotify::Artist.search(params[:search])
14
28
 
15
29
  end
16
30
 
31
+ end
32
+
17
33
  ```
18
34
 
35
+ ```search
36
+
37
+ <h3>アーティスト名で検索</h3>
38
+
39
+
40
+
41
+ <%= form_tag(controller:"musics",action:"index") do %>
42
+
43
+ <%= text_field_tag :search %>
44
+
45
+ <%= submit_tag 'Search',:name => nil %>
46
+
47
+ <% end %>
48
+
49
+
50
+
51
+ ```
52
+
19
- ```index.html.erb
53
+ ```index
20
54
 
21
55
  <% @artists.each do |artist| %>
22
56
 
23
57
  <h4><%= artist.name %></h4>
24
58
 
25
- <%= artist.images%>
26
-
27
59
  <% end %>
28
60
 
29
61
  ```
30
-
31
- ```<%= artist.images%>
32
-
33
- [{"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}]
34
-
35
- ```