search autocomplete

This commit is contained in:
Hipster Hitman
2011-04-10 10:17:06 +04:00
parent 47ee517b27
commit 424906baff
6 changed files with 46 additions and 3 deletions
+15
View File
@@ -9,5 +9,20 @@ class ArtistController < ApplicationController
end
@artist = Artist.getByName(name)
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