2

我正在努力让我的行动回应:htmland :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 数据。

但我所拥有的是,当我去时,/games.json我看到源代码/games及其布局等为 Json(application/json标题中的 HTML 代码)

4

1 回答 1

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?- 通过加兹勒

于 2011-05-10T11:25:46.033 回答