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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Smith <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Smith <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---