Dans mon contrôleur je:Rails Hash à tableau à hachage comment?
def index
@title = 'asdsadas'
@kategoris = Tag.where("name like ?", "%#{params[:q]}%")
@kate = @kategoris.map(&:attributes).map{|d| d.map{|d| d.map{|d| d.dup.force_encoding("UTF-8") if d.respond_to?(:force_encoding) } } }
respond_to do |format|
format.html
format.json { render :json => @kate }
end
end
Le problème est qu'il est devenu un tableau:
[[["cached_slug","vinna-biljetter"],["created_at",null],["h1","inn biljetter - Delta i tävl
Il devrait être un hachage:
[{"cached_slug":"vinna-biljetter","created_at":"2011-04-28T10:33:05Z","h1":"inn biljetter -
Essayez de mettre le tableau dans un hachage puis passer le hachage dans JSON. format.json {render: json => Hash [@kate]} Je ne suis pas sûr à 100% que cela fonctionnerait, mais essayez-le. – ericraio