Hi, everyone. I used a session in my model. but when I test this model. There said Error: NameError: undefined local variable or method `session'' for UserSetting:Class In UserSetting model, I use session like this: ... language= session[:lang] ... why? who know that, please tell me. Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Been awhile, but session is local to the controller not the model. If you want the model to use the session, you''ll have to pass the session to the model. OnRails wrote:> Hi, everyone. > I used a session in my model. but when I test this model. There said > Error: > NameError: undefined local variable or method `session'' for > UserSetting:Class > > In UserSetting model, I use session like this: > ... > language= session[:lang] > ... > why? who know that, please tell me. 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 -~----------~----~----~----~------~----~------~--~---
Thanks David Harkness! but I don''t know how to pass the session to the model, could you tell me how to do that? Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Fri, Nov 30, 2007 at 12:16:43PM -0800, OnRails wrote:> Thanks David Harkness! > but I don''t know how to pass the session to the model, could you tell > me how to do that?This is a fundamental design mistake. Your model layer should be entirely independent of the layers above it. Think about what you need from the session, why you think you need it, and how you could handle it without muddying the highly desirable separation of layers.> Thanks!--Greg --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi -- On Fri, 30 Nov 2007, OnRails wrote:> > Thanks David Harkness! > but I don''t know how to pass the session to the model, could you tell > me how to do that? > Thanks!Something like: class MyModel < AR::Base def do_something(session) ... end end and in a controller: m = MyModel.new m.do_something(session) Keep in mind, though, that models aren''t really supposed to have a sense of a "session". They just sort of sit there and do their thing. The controller should handle (i.e., control) the management of actual connections and sessions. David -- Upcoming training by David A. Black/Ruby Power and Light, LLC: * Intro to Rails, London, UK, December 3-6 (by Skills Matter) See http://www.rubypal.com for details and 2008 announcements! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks All! I think I got it. I will change this to controller Thanks again! On Nov 30, 12:23 pm, "David A. Black" <dbl...-0o/XNnkTkwhBDgjK7y7TUQ@public.gmane.org> wrote:> Hi -- > > On Fri, 30 Nov 2007, OnRails wrote: > > > Thanks David Harkness! > > but I don''t know how to pass the session to the model, could you tell > > me how to do that? > > Thanks! > > Something like: > > class MyModel < AR::Base > def do_something(session) > ... > end > end > > and in a controller: > > m = MyModel.new > m.do_something(session) > > Keep in mind, though, that models aren''t really supposed to have a > sense of a "session". They just sort of sit there and do their thing. > The controller should handle (i.e., control) the management of actual > connections and sessions. > > David > > -- > Upcoming training by David A. Black/Ruby Power and Light, LLC: > * Intro to Rails, London, UK, December 3-6 (by Skills Matter) > Seehttp://www.rubypal.comfor details and 2008 announcements!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---