2011-05-09 39 views
2

我試圖讓我的操作響應:html:jsonRails 3.1中`respond_with`和`respond_to`的意外行爲

class GamesController < ApplicationController 

    respond_to :html, :json 

    def index 
    @games = current_user.games 
    respond_with(@games) 
    end 

end 

預期的看法時,我去/games就是看views/games/index.haml佈局,如果我去/games.json我應該看到@games作爲broswer JSON數據。

但我有,當我去/games.json我看到的/games的源代碼,其佈局等爲JSON(HTML代碼在頭」

+0

一個錯字'@players = current_user.games'應該是'@games = current_user.games' – fl00r 2011-05-09 17:01:37

+0

錯字這裏不是我的應用程序!(編輯) – amrnt 2011-05-09 17:07:53

+2

views/games/index.haml應該是views/games/index.html.haml我剛剛檢查了一個我用erb製作的應用程序,它的工作正常......您是否嘗試過舊版的rails? – Gazler 2011-05-09 17:24:28

回答

2

您havve到文件的擴展application/json告訴Rails,我想使這個還是不

views/games/index.haml should be views/games/index.html.haml I just checked this with an app I made that uses erb and it works fine...Have you tried on an older version of rails? - !?通過 Gazler