# Access to @session object from model

**URL:** <https://www.ruby-forum.com/t/access-to-session-object-from-model/48588>\
**Category:** Ruby\
**Created:** [November 22, 2005, 1:44pm UTC](https://www.ruby-forum.com/t/access-to-session-object-from-model/48588 "2005-11-22T13:44:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mj-usunto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d07c76/32.png) [@mj-usunto](https://www.ruby-forum.com/u/mj-usunto)\
**Post date:** [November 22, 2005, 1:44pm UTC](https://www.ruby-forum.com/t/access-to-session-object-from-model/48588/1 "2005-11-22T13:44:51Z")

</div>

Hello  
I’m using login\_generator as authentication mechanism.  
I’m trying to make some logging system with sql as backend, and  
I need have access to @session object within models.  
Example code which won’t work (It dosn’t make anything) :  
before\_create { | record | a = @session[:user].id }  
I’m getting error like this:

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occured while evaluating nil.[]  
#{RAILS\_ROOT}/app/models/subscriber.rb:14

This line is line above ☹

Any suggestions or there is some sql base logging method for  
rails ??

---

<div class="post-metadata">

**Author:** ![mj-usunto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d07c76/32.png) [@mj-usunto](https://www.ruby-forum.com/u/mj-usunto)\
**Post date:** [November 22, 2005, 8:27pm UTC](https://www.ruby-forum.com/t/access-to-session-object-from-model/48588/2 "2005-11-22T20:27:44Z")

</div>

For Rails questions you’ll want to ask the Rails list because they  
have armies of Rails users there.

[http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Eric H. - removed\_email\_address@domain.invalid - [http://segment7.net](http://segment7.net)  
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

This implementation is HODEL-HASH-9600 compliant
