Skip to content

Instantly share code, notes, and snippets.

@JonnieCache
Forked from levinotik/controller
Created November 9, 2011 18:45
Show Gist options
  • Save JonnieCache/1352477 to your computer and use it in GitHub Desktop.
Save JonnieCache/1352477 to your computer and use it in GitHub Desktop.
class ArtistSearchController < ApplicationController
def search
@title = "Search"
end
def artist
@title = "Similar artists"
logger.debug "#{params[:artist].class}"
unless params.nil?
music_request = MusicRequest.new #snake_case, not camelCase
data = music_request.find_similar(params[:artist])
#using map to build arrays
@similar_artists = data[:response][:artists].map do |artist|
artist[:name]
end
logger.debug "#{data}"
end
end
def list_similar
@title = "amazing"
end
end
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
</head>
<body>
<h1>Similar artists</h1>
<p>
Here's a list of similar artists
</p>
<ul>
<% @similar_artists.each do |artist| %> #you only need the = in the <%= when that line will output something. this is just a loop. leave off the =
<li>
<%= artist %>
</li>
<% end %>
</ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment