2

I am building a rails3 application and I'm using the excellent 'gmail' gem to do some work with gmail. Each user enters his/her username and password and the gem creates a connection to gmail that can be used to fetch emails or send new emails.

How can I share this connection variable across actions in the same controller without having to create a new connection every time?

ex. user logs in with his details:

@gmail = Gmail.connect(email, pass)

then user clicks on a link that calls a different action, for example to read new emails:

@newemails = @gmail.inbox.count(:unread)

well the problem is that I cannot reuse this @gmail connection object in the 'unread' action as it is nil. I cannot store this in a session variable or in the database as it is not a string. And I cannot store this in a @@class_variable as the connection variable is not global across all sessions - each user must have its own connection obviously.

What is the best way to share this object across different actions?

Many thanks for your help, Alex

4

0 回答 0