Created
September 19, 2012 04:25
-
-
Save samuelkobe/3747690 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def vote | |
if !@hairstyle = Hairstyle.find_by_id(params[:id]) | |
redirect_to root_url, notice: 'Please select at least one hairstyle' | |
else | |
@client_ip = request.remote_ip | |
blacklist = Blacklist.find_by_ip(@client_ip) | |
if blacklist.try(:ip) == @client_ip | |
redirect_to root_url, notice: 'Looks like you\'ve voted recently, come back in 24hrs.' | |
else | |
if @hairstyle = Hairstyle.find_by_id(params[:id]) | |
@hairstyle.increment('count') | |
@hairstyle.save | |
Blacklist.create(:ip => @client_ip) | |
redirect_to root_url, notice: 'Thanks for Voting! Come back in 24hrs.' | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment