UPDATED: I am setting default scope for some models in a runtime which seems working locally in my development env and my code is given below.
SET_OF_MODELS = [Event, Group, User]
@account = Account.find_by_subdomain(account_subdomain) SET_OF_MODELS.each { |m| m.set_default_scope(@account.id) }
def set_default_scope(account_id) default_scope :conditions=> { :account_id => account_id } end
If I execute this code in ruby console with say @account1, User.first
returns @account1 user whereas if I repeat the code with @account2 then User.first
returns @account1 user instead of @account2. And this problem is not revealed while running app in local server but in staging server.
My guess is towards their states if they are really cached but not sure. Can someone explain in depth.
Thanks in advance
There is nothing wrong with the above code but the problem was with the server used i.e. thin server. It worked perfectly after replacing thin with mongrel. I think thin
wasn't allowing to execute set_default_scope more than once except after loading the application.