Nicolas Blanco
2006-Sep-11 12:24 UTC
Newb: use session and params in a model method : possible ?
Hi! How is it possible to use session or params in a model method ? # in a model (Demande.rb) def after_create user_id = session[:user_id] # ... end I get : undefined local variable or method `session'' for #<Demande:0x36f1fc8> I also tried with @session but I get a nil object. Thank you for your answers. Nicolas B. -- 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 -~----------~----~----~----~------~----~------~--~---
Curtis Summers
2006-Sep-11 13:04 UTC
Re: Newb: use session and params in a model method : possibl
Nicolas Blanco wrote:> Hi! > > How is it possible to use session or params in a model method ? > > > # in a model (Demande.rb) > def after_create > user_id = session[:user_id] > # ... > end > > I get : > > undefined local variable or method `session'' for #<Demande:0x36f1fc8> > > I also tried with @session but I get a nil object. > > Thank you for your answers. > Nicolas B.Just pass the desired session variable (or params variable) when creating the object: @post = Post.new(:user_id => session[:user_id]) -- 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 -~----------~----~----~----~------~----~------~--~---