1
0
Fork 0
oldhaven/app/controllers/artist_controller.rb

30 lines
685 B
Ruby

# encoding: utf-8
class ArtistController < ApplicationController
require 'open-uri'
def view
if params[:name].nil?
name = ''
else
name = params[:name].gsub('+', ' ').gsub('%20', ' ')
end
@artist = Artist.getByName(name)
pp @artist
end
def autocomplete
autocomplete = Artist.getLastFmAutocomplete(params[:query])
return render :nothing => true if autocomplete.nil?
suggestions = []
pp autocomplete["response"]
autocomplete["response"]["docs"].each do |doc|
suggestions << doc["artist"] unless suggestions.include?(doc["artist"])
end
render :json => {
:query => params[:query],
:suggestions => suggestions
}
end
end