title: Rails - How do I access a class in the parent model?
body: <p>I'm creating a user using omniauth gem (which is working), but after the <code>user</code> is created, I'd like to create a record in the <code>profile</code> table too (but only when a <code>user</code> is created).</p>
  
  <p>I decided to use a callback in the <code>user</code> model to do this.</p>
  
  <p>However, after the callback is performed and it hits my <code>create_profile</code> method, I run into an error regarding a method in the <code>user</code> model:</p>
  
  <pre><code>undefined method `facebook' for #&lt;Hash:0x007fdf16858200&gt;
  </code></pre>
  
  <p>Even though I'm passing user: self to the profile model, I am not able to access methods on it.</p>
  
  <p><strong>User.rb</strong></p>
  
  <pre><code>class User &lt; ActiveRecord::Base
  
  
      has_one :profile
      has_many :pins
      has_many :replies, through: :pins
  
  
      after_create :build_profile
  
  
      def self.from_omniauth(auth)
  
          where(auth.slice(:provider, :provider_id)).first_or_initialize.tap do |user|
  
              user.provider = auth.provider
              user.provider_id = auth.uid
              user.oauth_token = auth.credentials.token
              user.oauth_expires_at = Time.at(auth.credentials.expires_at)
              user.save
  
          end
  
      end
  
  
      def build_profile
  
          Profile.create_profile(user: self)
  
      end
  
  
      def facebook
  
          @facebook ||= Koala::Facebook::API.new(oauth_token)
  
      end
  
  
  end
  </code></pre>
  
  <p><strong>Profile.rb</strong></p>
  
  <pre><code>class Profile &lt; ActiveRecord::Base
  
  
      belongs_to :user
  
  
      def self.create_profile(user)
  
                  # undefined method `facebook' for #&lt;Hash:0x007fdf16858200&gt; for this line.
          user.facebook.inspect
  
      end
  
  end
  </code></pre>
  
  <p>I'm new to Ruby and Rails...so, please bear with me! </p>
  
  <p>I appreciate you looking this over and telling me where I'm going wrong.</p>
  
  <p>Thanks,
  Michael.</p>
  
  <p>PS - It seems <code>user.inspect</code> returns the result of a user in my <code>profile.rb</code> model...but I am trying to access the method on that user class. </p>