4

For some reason when I visit my index action on my rails application I get weird results. When its the first time i visit it, the results are as excpected, however, if I click on a link that takes me to another page and then press the back button, I get json results in my webpage verse HTML.

Here is my controller:

 class UsersController < ApplicationController
  respond_to :html, :json

  def index
    @users = User.all
    respond_with(@users) do |format|
        format.json {
            render :json => @users.to_json(:methods => :available)
        }
    end
  end

end

2 Answers2

0

I found a something here, maybe it can

Chrome caches the pages you visit and when you go back or forward it uses the cache to display the page quickly. If the URLs you are using to retrieve JSON from the server by AJAX is the same one Chrome would hit, then it's possible Chrome is picking that page from the cache, which instead of being the nice HTML it's just a JSON dump.

Community
  • 1
  • 1
0

Add format.html to the respond_with block. Add resp. views for the request formats under views and it should work fine.

GSS
  • 71
  • 4