Showing posts with label Thread. Show all posts
Showing posts with label Thread. Show all posts

Sunday, October 31, 2010

Rails Application variable

It almost seemed that there was no easy way out of putting application scope variables in the database.
But there is a way out:
    if Thread.main[:uuid] == nil
      Thread.main[:uuid]=0
    end
    uid = Thread.main[:uuid] += 1


This code accesses the mail thread of the rails process and puts a variable on it. (the thread is an object and can have key => value sets)
And since rails has only one main thread... its shared with all the threads underneath.

Good Luck