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

32 lines
780 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
2011-04-11 03:12:06 +00:00
if request.request_method == 'POST'
redirect_to :action => 'view', :name => params[:name].gsub(' ', '+')
end
name = params[:name].gsub('+', ' ')
end
@artist = Artist.getByName(name)
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