2013-02-10 18 views
0

JSON響應我有一個簡單的方法如何使用Rails的

def country_list 

    @countries = User.find(:all).map(&:country).uniq 

    render :json => @countries 

    end 

,如果它的路徑是country_list_path,我怎麼可以使用響應作爲例如自動完成源列表,或者只顯示?

如果我把任何地方country_list_path我會得到的網址,而不是響應

回答

0

如果您想直接獲取JSON數據,你應該把User.find(:all).map(&:country).uniq.to_json而不是檢索數據的URL的。