passing value from controller to model

Is it possible to manually pass a value to the model from a


I'm not sure what you mean. Obviously from your controller you can do
some_object.something = :foo


some_object.create(:foo => 'Bob' , :bar => 23)

If you gave an example of what you were trying to do someone might be able to construct a more meaningful answer.


I am using restful_authentication with attachment_fu. I want to have
the file directory used based on the user_id so that every user has
its own directory. I tried modifying the path_prefix (the variable
that specifies which folder to use) in the
controller, this made the change within the database but it still
saves the file in the default directory (public/fileupload)
Here is the code

  @fileupload.path_prefix = 'public/tester' +

The plugin will only use the folder specified in the model and not the
controller. I don't have access to the userid in the upload model (its
only present in the controllers). So I was wondering if I can pass in
the userId from the controller into the model somehow.

I think that the right way to do this is to override the method
full_filename in your model

Here's the default implementation (in
        # Gets the full path to the filename in this format:


Thanks for your response

Unfortunately only the controller has access to the user id. So I
can't make the foldername based on the user id in the model. Is there
anyway I can pass the value from the controller to the model?

Of course there is! Define a method in the model:

def method(user_id)


and then call it from the controller, passing in user_id.

Not working :frowning:
I get
undefined method `printval' for #<FileuploadController:0x57fea90>

i created a def printval(userid) in the model. I even tried passing
the value in the session in the controller but I can't even seem to
access sessions in the model

You should be calling it on an instance of the model, For example

file_upload = FileUpload.find(:first)