class User < ActiveRecord::Base
@facebook ||= Koala::Facebook::API.new(oauth_token)
user = User.first
What do you mean by getting replaced?
From what I see when initializing API (
API.new(oauth_token)) you are passing
ouath_token that is assigned to specific user. When calling
User.first you're loading first user from database, and ActiveRecord automatically assigns oauth_token to newly created instance. If ouath_token was never saved (thus present in db record) it would be
This is in general done for performance reasons in order to avoid multiple API calls within same request. However, usually response from API call is cached not the API instance itself. Maybe that Koala API instance calls webservice directly in constructor (in its
My note - keeping such methods like
User model ends with very difficult to change code.
It's better to move it somewhere out from this model.