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!
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 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.