Problems caching Rails?

For some reason, when I visit my index action in my rails application, I get strange results. When it is the first time I find it, the results are checked, however, if I click on the link that leads me to another page and then click the back button, I get the json results on the HTML verse webpage.

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 
+4
source share
2 answers

Add format.html to the response_with block. Add accordingly. views for query formats under views, and it should work fine.

0
source

I found something here , maybe he can

Chrome caches the pages you visit, and when you return or forward them, it uses the cache to quickly display the page. If the URLs you use to get JSON from the AJAX server is the same as Chrome. click, then it is possible that Chrome selects this page from the cache, which, instead of being good HTML, is just a JSON dump.

0
source

Source: https://habr.com/ru/post/1387407/


All Articles