1

I have an app with operations such as delete that redirect_to (:back) to a page where the delete button is. Whenever it goes back to the page the deleted item still appears as if the item still exists. Is there a way to refresh the page to show the updated state of the object when going back to the page?

Joe Essey
  • 3,457
  • 8
  • 40
  • 69
  • Wouldn't it be preferable to just redirect somewhere else after the delete? Maybe to the index for that resource or something? It doesn't seem to make sense to go back to a page with something that doesn't exist anymore. – Scott S Apr 19 '13 at 13:50
  • It's actually a case when a user chooses to modify the object from an index page. They are taken to an edit form. When the user manually backs out to the index page again, they must reload to get the updated view of the index. – Joe Essey Apr 19 '13 at 13:56
  • I can't think of a very good solution for achieving this, aside from intercepting the back button, which I don't consider good practice (I find those "Are you sure you want to leave this page?" confirmations a bit maddening). After actions such as edit and delete are completed, I would just redirect to the index, or wherever it is most appropriate for the users' workflow, provide comprehensive navigation anywhere the user may need to go, and not worry about browser navigation. I was typing a much longer explanation, but this really isn't the medium for it. If you want it we can start a chat. – Scott S Apr 19 '13 at 14:18

1 Answers1

1

I added the following method in the application_controller to prevent the index pages from caching.

def set_cache_buster
    response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
    response.headers["Pragma"] = "no-cache"
    response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end

Added this filter to pages I wanted to control:

before_filter :set_cache_buster

Thanks @Jason Butler.

How to prevent browser page caching in Rails

Community
  • 1
  • 1
Joe Essey
  • 3,457
  • 8
  • 40
  • 69