Forum: Ruby on Rails Getting a user from a model (sort of a noob)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
11bd67aedc131020a51440fad59116cc?d=identicon&s=25 Andrew Filipowski (Guest)
on 2006-01-10 14:07
(Received via mailing list)
As mentioned in my previous posts I'm trying to create a dynamic
directory for file_folumn. After finding out that I didn't have the
most recent version I installed the latest trunk and am able to get
file_column to act as it should. However I have been racking my brain
on how to implement finding my current user from a model. I have
tried everything in my basic/getting better knowledge of Rails and
Ruby but have been striking out so far no luck. I am assuming others
have done this so just some tips on how to get at this info would be
greatly appreciated. The model that I am trying to get at the user
info from does have a belongs_to relationship to my user. Here is my
last attempt which comes back with a user can't be found without an
ID=0 error:

File.join("test",User.find(self.user_id).companyname,"image")

I have also tried:

File.join("test",User.find(self.user.id).companyname,"image")

And receive the Called id for nil, which would mistakenly be 4 -- if
you really wanted the id of nil, use object_id error message. By my
knowledge this makes sense as the object that I am creating has not
totally been saved yet but I thought that by calling an Object.new
(params[:object]) that the object at least resides in memory at this
point (I am doing the object.new at the beginning of my create method
in the controller for that model). Am I on the right path here or
just running around in circles?

Thanks for all the help from everyone on the list without it I would
be having a much harder time than I am getting my head wrapped around
Ruby and Rails (I am working under a deadline and have been forced to
learn at the same time that I am writing a product for release for
our company)

Andrew
This topic is locked and can not be replied to.