我试图让我的行为响应: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时,应该会在broswer中将@games作为json数据查看。
但我所拥有的是,当我转到/games.json时,我看到/games的源代码及其布局等都是json(头部带有application/json的html代码)

最佳答案

你必须使用文件的扩展名来告诉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

关于ruby-on-rails - Rails 3.1中`respond_with`和`respond_to`的异常行为,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5940059/

10-13 01:00