Last active
October 15, 2015 22:46
-
-
Save sankalpk/3decad3a876674257ce2 to your computer and use it in GitHub Desktop.
Post once exactly in Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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