# 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