# encoding: utf-8 class ArtistController < ApplicationController require 'open-uri' def view if params[:name].nil? name = '' else if request.request_method == 'POST' redirect_to :action => 'view', :name => params[:name].gsub(' ', '+') end name = params[:name].gsub('+', ' ') 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