我正在尝试让我的操作回复:html
和:json
。
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
作为JSON数据broswer。
但我得到的是,当我转到/games.json
时,我看到/games
的源代码及其布局等为Json(标题中带有application/json
的HTML代码“
答案 0 :(得分:2)
你必须扩展文件以告诉我想要渲染的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