how to access variable in 3 level (model,controller,view) i use session[:current_unit] only can in C and V can''t access in M i mean is use a goloble variable can access in anywhere Such as: user slecet a Unit, in model, before User.save the user.unit_id must set session[:user_id] in login form User must select a unit , this is current_unit, I save it in session[:user_id] but how can i get it in model or there are an other mothed to handle it? 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-May-09 15:12 UTC
Re: how to access variable in 3 level (model,controller,vie
Fuyi wrote:> how to access variable in 3 level (model,controller,view) > > i use session[:current_unit] only can in C and V > can''t access in M > > i mean is use a goloble variable can access in anywhereYou probably don''t want to use a global variable for this.> > Such as: > user slecet a Unit, > in model, before User.save the user.unit_id must set > session[:user_id] > in login form User must select a unit , this is current_unit, I > save it in session[:user_id] > but how can i get it in model > or there are an other mothed to handle itIt sounds like you''re not going about this correctly. Can you give more details of what you''re trying to do?> > thanks!Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Vladimir Rybas
2010-May-09 19:17 UTC
Re: how to access variable in 3 level (model,controller,view)
In declarative_authorization you can do before_filter {|c| Authorization.current_user = c.current_user} in ApplicationController, then call using_access_control in Model, and you get current_user(or something like that) in your model. Check how they do it. Also, there is a hack from @lifo(Rails core team and 37signals member) http://m.onkey.org/2007/10/17/how-to-access-session-cookies-params-request-in-model On Sun, May 9, 2010 at 9:19 PM, Fuyi <fuyi.it-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> how to access variable in 3 level (model,controller,view) > > i use session[:current_unit] only can in C and V > can''t access in M > > i mean is use a goloble variable can access in anywhere > > Such as: > user slecet a Unit, > in model, before User.save the user.unit_id must set > session[:user_id] > in login form User must select a unit , this is current_unit, I > save it in session[:user_id] > but how can i get it in model > or there are an other mothed to handle it? > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.