Skip to content

Instantly share code, notes, and snippets.

@samuelkobe
Created September 19, 2012 04:25
Show Gist options
  • Save samuelkobe/3747690 to your computer and use it in GitHub Desktop.
Save samuelkobe/3747690 to your computer and use it in GitHub Desktop.
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