Is it thread safe to set Active Resource HTTP authentication on a per-user basis?

Monkey patch the host, user and password methods of ActiveResource::Base class: class ActiveResource::Base # store the attribute value in a thread local variable class << self %w(host user password).each do |attr| define_method(attr) do Thread.current[“active_resource.#{attr}”] end define_method(“#{attr}=”) do |val| Thread.current[“active_resource.#{attr}”] = val end end end end Now set the credentials in every request class ApplicationController < … Read more

How do I set and access attributes of a class? [duplicate]

The answer, in a few words In your example, itsProblem is a local variable. Your must use self to set and get instance variables. You can set it in the __init__ method. Then your code would be: class Example(object): def __init__(self): self.itsProblem = “problem” theExample = Example() print(theExample.itsProblem) But if you want a true class … Read more