ruby on rails - Does ActionDispatch instance can't be stored in a class variable? -



ruby on rails - Does ActionDispatch instance can't be stored in a class variable? -

i have controller has 2 methods: upload , submit

i can ensure upload method executed before submit called.

in upload, have such code:

def upload @file = params[:avatar] ... end

in submit, have such code:

def submit ... user.avatar = @file ... end

but seems @file nil.

where wrong?....

i'm using rails 3.2.0

instance variables in controllers not persist between requests. every request creates new instance of controller class @file save in upload goes away when upload finishes. then, when new request comes in routed submit method, rails create new instance of controller class , phone call submit on it. since have 2 instances of class, have 2 sets of instance variables , won't share @file.

you have arrange @file stored in database, session, form, etc. between requests , submit has load ever stored , assign user.avatar.

ruby-on-rails ruby-on-rails-3

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -