Skip to content

Commit

Permalink
Added: Both
Browse files Browse the repository at this point in the history
Changed --> use global instead of a constant
  • Loading branch information
nathanbertram committed May 31, 2011
1 parent f7d4ff4 commit b1fed52
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
10 changes: 6 additions & 4 deletions app/controllers/press_shift_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ def index
def press
if cookies[:pressed].present?
# DO NOTHING!!!
elsif params[:button] == "left"
$redis.incr('left_count')
elsif params[:button] == "right"
$redis.incr('right_count')
elsif params[:button] == 'left'
REDIS.incr('left_count')
elsif params[:button] == 'both'
REDIS.incr('both_count')
elsif params[:button] == 'right'
REDIS.incr('right_count')
end
cookies.permanent[:pressed] = params[:button]
redirect_to root_path
Expand Down
10 changes: 8 additions & 2 deletions app/views/press_shift/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
- if @cookie
%p
Left Count:
= $redis.get('left_count')
= REDIS.get('left_count')
%p
Both Count:
= REDIS.get('both_count')
%p
Right Count:
= $redis.get('right_count')
= REDIS.get('right_count')

- else
= link_to "Left", press_path(:button => "left"), :method => :post
|
= link_to "Both", press_path(:button => "both"), :method => :post
|
= link_to "Right", press_path(:button => "right"), :method => :post
6 changes: 3 additions & 3 deletions config/initializers/redis.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if Rails.env.production?
uri = URI.parse(ENV["REDISTOGO_URL"])
$redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
redis_uri = URI.parse(ENV["REDISTOGO_URL"])
REDIS = Redis.new(:host => redis_uri.host, :port => redis_uri.port, :password => redis_uri.password)
else
$redis = Redis.new(:host => 'localhost', :port => 6379)
REDIS = Redis.new(:host => 'localhost', :port => 6379)
end
5 changes: 3 additions & 2 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,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)
REDIS.set('left_count', 0)
REDIS.set('right_count', 0)
REDIS.set('both_count', 0)

0 comments on commit b1fed52

Please sign in to comment.