Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
# Code sample to determine if a user has been recently online # Using restful_authentication or acts_as_authenticated # By emili.parreno AT gmail.com // jaimeiniesta AT gmail.com ## migration to add last_seen_at to users class AddLastSeenAtToUsers < ActiveRecord::Migration def self.up add_column :users, :last_seen_at, :datetime, :default => "2000-01-01" end def self.down remove_column :users, :last_seen_at end end ## apps/controllers/application.rb class ApplicationController < ActionController::Base before_filter :update_last_seen_at def update_last_seen_at if logged_in? and current_user.last_seen_at + 5.minutes < Time.now current_user.update_attribute("last_seen_at" ,Time.now) end end end ## apps/models/user.rb class User < ActiveRecord::Base def is_online? last_seen_at + 5.minutes > Time.now end end
This paste will be private.
From the Design Piracy series on my blog: