I am making calls to an ActiveResource object inside an engine, and I need to set the headers in a thread safe way.
I have /lib/mymodule.rb in the engine and it looks something like this:
module MyModule
def self.my_method()
begin
data = WebResource.find(:all) # Where WebResource < ActiveResource::Base
rescue
data = nil
end
return data
end
end
Then in my views/controllers, I call this method roughly like this:
WebResource.headers[:some_id] = cookies[:some_id]
MyModule::my_method()
After asking this question and doing some reading, it looks like this is not threadsafe because I set headers at the class-level.
What is the best way to set these headers in a thread safe way?