Module | Authlogic::Session::Scopes::ClassMethods |
In: |
lib/authlogic/session/scopes.rb
|
What with_scopes focuses on is scoping the query when finding the object and the name of the cookie / session. It works very similar to ActiveRecord::Base#with_scopes. It accepts a hash with any of the following options:
Here is how you use it:
UserSession.with_scope(:find_options => {:conditions => "account_id = 2"}, :id => "account_2") do UserSession.find end
Eseentially what the above does is scope the searching of the object with the sql you provided. So instead of:
User.where("login = 'ben'").first
it would be:
User.where("login = 'ben' and account_id = 2").first
You will also notice the :id option. This works just like the id method. It scopes your cookies. So the name of your cookie will be:
account_2_user_credentials
instead of:
user_credentials
What is also nifty about scoping with an :id is that it merges your id‘s. So if you do:
UserSession.with_scope(:find_options => {:conditions => "account_id = 2"}, :id => "account_2") do session = UserSession.new session.id = :secure end
The name of your cookies will be:
secure_account_2_user_credentials