Skip to content

Instantly share code, notes, and snippets.

@sankalpk
Last active October 15, 2015 22:46
Show Gist options
  • Save sankalpk/3decad3a876674257ce2 to your computer and use it in GitHub Desktop.
Save sankalpk/3decad3a876674257ce2 to your computer and use it in GitHub Desktop.
Post once exactly in Rails
# Put in controller action
def create
post_once_exactly(params[:uuid]) do
# do some stuff
end
end
# Put in API base controller
def post_once_exactly uuid
if(uuid.nil? || !$redis.sadd("post_requests", uuid))
render "api/errors/duplicate_request", status: 405
else
yield
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment