Skip to content

Instantly share code, notes, and snippets.

Created October 30, 2016 00:24
Show Gist options
  • Save anonymous/6c98534fb5508bb378dad680649b7175 to your computer and use it in GitHub Desktop.
Save anonymous/6c98534fb5508bb378dad680649b7175 to your computer and use it in GitHub Desktop.
Prevent Users from Submitting duplicate forms
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
private
def client_will_not_cache_response
response.headers["Cache-Control”] = “no-cache, no-store”
response.headers[“Pragma”] = “no-cache”
response.headers[“Expires”] = “Fri, 01 Jan 1990 00:00:00 GMT”
end
end
class PuppiesController < ApplicationController
before_filter :redirect_if_existing, only: [:new, :create]
after_filter :browser_will_not_cache_response, only: [:new]
private
def redirect_if_existing
## If user already has a record in the puppies table
## created this year
## then redirect them to edit that Puppy.
## Be a courteous host and alert user that they were redirected.
end
end
@rskelley9
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment