Skip to content

Commit

Permalink
Ugly, but it works
Browse files Browse the repository at this point in the history
  • Loading branch information
Skipants committed May 31, 2011
1 parent 40b3b6e commit 6f484c3
Show file tree
Hide file tree
Showing 17 changed files with 2,344 additions and 296 deletions.
10 changes: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ gem 'rails', '3.0.7'

gem 'sqlite3'

gem 'redis'

# rake fix
gem 'rake', '~> 0.8.7'

gem 'haml'

# As suggested by Redis
gem 'SystemTimer'

# Use unicorn as the web server
# gem 'unicorn'

Expand Down
9 changes: 8 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
GEM
remote: http://rubygems.org/
specs:
SystemTimer (1.2.3)
abstract (1.0.0)
actionmailer (3.0.7)
actionpack (= 3.0.7)
Expand Down Expand Up @@ -32,6 +33,7 @@ GEM
builder (2.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
haml (3.1.1)
i18n (0.5.0)
mail (2.2.19)
activesupport (>= 2.3.6)
Expand All @@ -58,7 +60,8 @@ GEM
activesupport (= 3.0.7)
rake (>= 0.8.7)
thor (~> 0.14.4)
rake (0.9.0)
rake (0.8.7)
redis (2.2.0)
sqlite3 (1.3.3)
thor (0.14.6)
treetop (1.4.9)
Expand All @@ -69,5 +72,9 @@ PLATFORMS
ruby

DEPENDENCIES
SystemTimer
haml
rails (= 3.0.7)
rake (~> 0.8.7)
redis
sqlite3
15 changes: 15 additions & 0 deletions app/controllers/press_shift_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class PressShiftController < ApplicationController
def index
@cookie = cookies[:pressed]
end

def press
if params[:button] == "left"
$redis.incr('left_count')
elsif params[:button] == "right"
$redis.incr('right_count')
end
cookies.permanent[:pressed] = params[:button]
redirect_to root_path
end
end
2 changes: 2 additions & 0 deletions app/helpers/press_shift_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module PressShiftHelper
end
14 changes: 14 additions & 0 deletions app/views/press_shift/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%h1
Which Shift Button?

- if @cookie
%p
Left Count:
= $redis.get('left_count')
%p
Right Count:
= $redis.get('right_count')

- else
= link_to "Left", press_path(:button => "left"), :method => :post
= link_to "Right", press_path(:button => "right"), :method => :post
1 change: 1 addition & 0 deletions config/initializers/redis.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$redis = Redis.new(:host => 'localhost', :port => 6379)
58 changes: 2 additions & 56 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,58 +1,4 @@
WhichShiftButton::Application.routes.draw do
# The priority is based upon order of creation:
# first created -> highest priority.

# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action

# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)

# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products

# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end

# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end

# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end

# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end

# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => "welcome#index"

# See how all your routes lay out with "rake routes"

# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id(.:format)))'
root :to => 'press_shift#index'
match '/press' => 'press_shift#press', :as => :press
end
15 changes: 15 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 0) do

end
3 changes: 3 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
#
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Mayor.create(:name => 'Daley', :city => cities.first)

$redis.set('left_count', 0)
$redis.set('right_count', 0)
Loading

0 comments on commit 6f484c3

Please sign in to comment.