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

30 lines
685 B
Ruby
Raw Normal View History

2011-04-05 22:58:11 +00:00
# encoding: utf-8
2011-04-03 16:21:05 +00:00
class ArtistController < ApplicationController
2011-04-05 22:58:11 +00:00
require 'open-uri'
2011-04-03 16:21:05 +00:00
def view
if params[:name].nil?
name = ''
else
name = params[:name].gsub('+', ' ').gsub('%20', ' ')
end
@artist = Artist.getByName(name)
2011-04-10 00:15:29 +00:00
pp @artist
2011-04-03 16:21:05 +00:00
end
2011-04-10 06:17:06 +00:00
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
2011-04-03 16:21:05 +00:00
end