Skip to content

Instantly share code, notes, and snippets.

View samuelkobe's full-sized avatar
🐃
Pushing

Samuel Kobe samuelkobe

🐃
Pushing
View GitHub Profile
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])
Started POST "/hairstyles/vote" for 127.0.0.1 at 2012-09-17 16:14:01 -0700
Processing by HairstylesController#vote as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"t/Km9bYCNZWFcebozXqmVB2Gpta1C8W07l0kqkiLjS0=", "id"=>"6", "commit"=>"Vote"}
Redirected to http://hairapp.dev/hairstyles/vote?id=6
Filter chain halted as :ip_check rendered or redirected
Completed 302 Found in 1ms (ActiveRecord: 0.0ms)
Started GET "/hairstyles/vote?id=6" for 127.0.0.1 at 2012-09-17 16:14:01 -0700
Started POST "/hairstyles/vote" for 127.0.0.1 at 2012-09-17 16:00:51 -0700
Processing by HairstylesController#vote as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"t/Km9bYCNZWFcebozXqmVB2Gpta1C8W07l0kqkiLjS0=", "hairstyle"=>"6", "commit"=>"Vote"}
Hairstyle Load (0.2ms) SELECT "hairstyles".* FROM "hairstyles" WHERE "hairstyles"."id" = ? LIMIT 1 [["id", "6"]]
Redirected to http://hairapp.dev/hairstyles/vote?hairstyle=6
Filter chain halted as :ip_check rendered or redirected
Completed 302 Found in 8ms (ActiveRecord: 0.6ms)
Started POST "/hairstyles/vote" for 127.0.0.1 at 2012-09-17 15:59:04 -0700
Processing by HairstylesController#vote as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"t/Km9bYCNZWFcebozXqmVB2Gpta1C8W07l0kqkiLjS0=", "hairstyle"=>"6", "commit"=>"Vote"}
Hairstyle Load (0.1ms) SELECT "hairstyles".* FROM "hairstyles" WHERE "hairstyles"."id" = ? LIMIT 1 [["id", "6"]]
 (0.1ms) begin transaction
Hairstyle Exists (0.1ms) SELECT 1 AS one FROM "hairstyles" WHERE ("hairstyles"."name" = 'Let It Grow' AND "hairstyles"."id" != 6) LIMIT 1
 (0.3ms) UPDATE "hairstyles" SET "count" = 10, "updated_at" = '2012-09-17 22:59:04.575039' WHERE "hairstyles"."id" = 6
 (2.5ms) commit transaction
<%= form_tag(:controller => 'hairstyles', :action => 'vote') do %>
<% Hairstyle.all.each do |hairstyle| %>
<ul style="float:left;">
<li><%= radio_button_tag 'id', hairstyle.id %></li>
<li class="name"><%= hairstyle.name %></li>
<li class="count"><%= hairstyle.count %></li>
</ul>
<% end %>
<%= submit_tag 'Vote' %>
<% end %>
class HairstylesController < ApplicationController
before_filter :ip_check, :only => [:vote]
def vote
if @hairstyle = Hairstyle.find(params[:id])
@hairstyle.increment('count')
@hairstyle.save
redirect_to root_url, notice: 'Thanks for Voting'
end
@samuelkobe
samuelkobe / gist:3736006
Created September 17, 2012 07:17
hello
<div class="row-fluid" id="hairstyles">
<%= form_tag('/blacklists/ip_check') do %>
<% Hairstyle.all.each do |hairstyle| %>
<ul style="float:left;">
<li><%= radio_button_tag 'hairstyle', hairstyle.id %></li>
<li class="name"><%= hairstyle.name %></li>
<li class="count"><%= hairstyle.count %></li>
</ul>
<% end %>
<%= submit_tag 'Vote' %>
@samuelkobe
samuelkobe / blog html
Created July 22, 2012 06:41
Showing matt Gist2
<!DOCTYPE html>
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<head>
@samuelkobe
samuelkobe / html
Created July 22, 2012 06:31
Showing matt Gist
<!DOCTYPE html>
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<head>