Sha256: 377188c108ea2997c7db2f692a2c164b5f48b0f6a22bbd134c94fe2e2b6a738a
Contents?: true
Size: 1.32 KB
Versions: 11
Compression:
Stored size: 1.32 KB
Contents
-------------------------------- NAME -------------------------------- rails_current -------------------------------- DESCRIPTION -------------------------------- track 'current_user' et all in a tidy, global, and thread-safe fashion. -------------------------------- SYNOPSIS -------------------------------- most rails apps scatter a bunch of @current_foobar vars everywhere. don't do that. it's fugly. instead, do this. declare the current_XXX variables you'll want tracked. you can pass a block for lazy computation class ApplicationController Current(:user){ User.find session[:current_user } Current(:account) end you can now access the current state two ways 1) globally from anywhere in your code base if Current.user ... end Current.user = User.find(id) 2) or using the current_ methods that are added by including the Current module into any class (ActionController::Base and ActionView::Base automatically include it) if current_user ... end self.current_user = User.find(id) the Current module is cleared out before every request and is thread safe. -------------------------------- INSTALL -------------------------------- gem install rails-current gem 'rails-current', :require => 'current' bundle install
Version data entries
11 entries across 11 versions & 1 rubygems