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.

Nicolas B. 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])