Rails 3.1中`respond_with`和`respond_to`的意外行为

时间:2011-05-09 16:58:29

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.1

我正在尝试让我的操作回复: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代码“

1 个答案:

答案 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