# Quick validation question

**URL:** <https://www.ruby-forum.com/t/quick-validation-question/133305>\
**Category:** Rails\
**Created:** [March 29, 2008, 9:54pm UTC](https://www.ruby-forum.com/t/quick-validation-question/133305 "2008-03-29T21:54:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [March 29, 2008, 9:54pm UTC](https://www.ruby-forum.com/t/quick-validation-question/133305/1 "2008-03-29T21:54:15Z")

</div>

Hi, just a quick one. How can I access session values in validation?  
Here’s what I’m trying to do…

validates\_numericality\_of :points, :less\_than\_or\_equal\_to =\>  
session[:user][:points]

And this is the message I get  
undefined local variable or method `session’ for #Class:0x5181a8c

Any help would be appreciated. Thanks.

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [March 30, 2008, 4:31pm UTC](https://www.ruby-forum.com/t/quick-validation-question/133305/2 "2008-03-30T16:31:00Z")

</div>

Unless I’m mistaken, session information is not directly available to  
a model. You could hack together some validation in the controller  
(not recommended), try sending the session info to the model via a  
function, or better yet, find some other place to store this info.

-Kyle

On Mar 29, 3:54 pm, Dan S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [March 31, 2008, 3:30pm UTC](https://www.ruby-forum.com/t/quick-validation-question/133305/3 "2008-03-31T15:30:24Z")

</div>

Kyle’s right – you’re out past thin ice here. ‘session’ is a  
controller issue that’s not really related to your domain (models).  
It’s much too fleeting.

What model is validating its ‘points’? How is it related to user? I  
think if you start working down that road you’ll find a solution  
that’s workable (ie., validate directly or indirectly through user).

On Mar 29, 4:54 pm, Dan S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
