amrnt
amrnt

Reputation: 1331

Unexpected behavior for `respond_with` and `respond_to` in Rails 3.1

I'm trying to make my actions respond to :html and :json.

class GamesController < ApplicationController

  respond_to :html, :json

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

end

The expected view when I go to /games is to see the layout of views/games/index.haml and if I go to /games.json I should have see the @games as JSON data in the broswer.

But what I have is, when I go to /games.json I see the source code of /games with its layout etc as Json (HTML code with application/json in the header"

Upvotes: 2

Views: 550

Answers (1)

amrnt
amrnt

Reputation: 1331

You havve to the extension of the files to tell Rails that i want to render this or not!

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? - via Gazler

Upvotes: 2

Related Questions