Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Commit

Permalink
Remember my last session
Browse files Browse the repository at this point in the history
Using new Cookie (tm) Technology, Tomatoist now remembers your last
session and sends you back to it when you return!!
  • Loading branch information
mrmemes-eth committed Mar 7, 2012
1 parent 16caf00 commit 9eefd38
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ group :test do
end

gem 'padrino', '~> 0.10.5'
gem 'padrino-cookies', '~> 0.1.0'
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ GEM
padrino-helpers (= 0.10.5)
padrino-cache (0.10.5)
padrino-core (= 0.10.5)
padrino-cookies (0.1.0)
padrino-core
padrino-core (0.10.5)
activesupport (~> 3.1.0)
http_router (~> 0.10.2)
Expand Down Expand Up @@ -172,6 +174,7 @@ DEPENDENCIES
mocha (~> 0.10.4)
mongoid (~> 2.4.4)
padrino (~> 0.10.5)
padrino-cookies (~> 0.1.0)
rack_hoptoad
rake
rspec (~> 2.8.0)
Expand Down
1 change: 1 addition & 0 deletions app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class Tomatoist < Padrino::Application
register HoptoadInitializer
register Padrino::Mailer
register Padrino::Helpers
register Padrino::Cookies

##
# Application configuration options
Expand Down
8 changes: 7 additions & 1 deletion app/controllers/main.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
Tomatoist.controller do
get '/' do
redirect session_path(Session.create)
if cookies.has_key?(:current_session)
redirect "/#{cookies[:current_session]}"
else
redirect session_path(Session.create)
end
end

get '/faq' do
render(:haml, :faq, layout: :application)
end

get '/:session/?' do
return if params[:session] == 'null'
cookies.permanent[:current_session] = params[:session]
@session = Session.retrieve(params[:session])
render(:haml, :timers, layout: :application)
end
Expand Down

0 comments on commit 9eefd38

Please sign in to comment.