Getting the Session from a Model

I have justs started a file upload applciation. I am using the
Login_Sugar project as well. It has a User model. My file upload has a
Content model. The contents table has a foreign_key constrains on the
users table (in other words, each piece of content is owned by one
user).

The upload controller passes control to the Content model which needs to
define the “user” member. This is kept in the session and can be
accessed by the controller via “session[:user]”.

How do I pas the session or the user object to the model?

Note: I’m sure there must be a standard and easy way to do this. A way
that does not involve passing another parameter to the Content’s
constructor.

I tried writing a class method in the controller to simply return the
session[:user] but when called from the context of the Content model it
always returns nil (the session is nil at this point).

Any ideas ont is would beappreciated. I’m new to Ruby+Rails.

creates a new content object from the params sent by the upload form

content = Content.new(params[:content])

adds the user association, this assumes the user OBBJECT is stored in

session
content.user = session[:user]

save the new Content object

content.save!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs