Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8152313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:40:28+00:00 2026-06-06T15:40:28+00:00

I am working on rails 3 app and using the koala gem to get

  • 0

I am working on rails 3 app and using the koala gem to get a connection to the facebook graph api.I am also using omniauth to autenticate users.

I get the following error:

NoMethodError in SessionsController#create
undefined method `add_friends' for #<User:0x007fcfcb1a87e8>

app/models/user.rb:28:in `block in from_omniauth'
app/models/user.rb:6:in `tap'
app/models/user.rb:6:in `from_omniauth'
app/controllers/sessions_controller.rb:3:in `create'

In ruby docs it says: “Raised when a method is called on a receiver which doesn’t have it defined and also fails to respond with method_missing.”

But I have a metod defined, so why do I get this error? And how can I fix it?

In my SessionController I do something like this:

class SessionsController < ApplicationController
  def create
    user = User.from_omniauth(env['omniauth.auth'])
    session[:user_id] = user.id
    redirect_to root_url, notice: "Signed in!"
  end
end

This is my user model:

class User < ActiveRecord::Base
  #attr_accessible :provider, :uid, :token, :email, :name, :first_name, :last_name, :image, :gender, :location, :school, :year
  has_many :friends

  def self.from_omniauth(auth)
    where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
      user.provider = auth["provider"]
      user.uid = auth["uid"]
      user.name = auth["info"]["name"]
      user.first_name = auth["info"]["first_name"]
      user.last_name = auth["info"]["last_name"]
      user.image = auth["info"]["image"]
      user.email = auth["info"]["email"]
      user.gender = auth["extra"]["raw_info"]["gender"]
      user.location = auth["extra"]["raw_info"]["location"]["name"]          
      user.token = auth["credentials"]["token"]

      user.add_friends
      user.save!
      user

    end

    def add_friends
      @facebook.get_connections("me", "friends").each do |hash|
        self.friends.find(:name => hash['name'], :uid => hash['id']).first_or_create
      end
    end

    private 

    def facebook
      @facebook ||= Koala::Facebook::API.new(token)
    end
  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:40:30+00:00Added an answer on June 6, 2026 at 3:40 pm

    In the code you posted def add_friends is actually inside your from_omniauth class method and so ends up being a class method too, rather than an instance method.

    Move that (and the facebook method) out of there and you should be ok. You probably also want to be calling your facebook method rather than accessing the instance variable directly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get Facebook logins working on my app using Rails, Authlogic, and
I have jquery working on my Rails app using the gem 'jquery-rails' . I
I'm working to integrate facebook in my app. To do that I'm using koala,
I am trying to get a Rails app working on my web host. Using
I am working on a rails app which uses a gem also in development.
I'm using the Paperclip gem with a Rails 3.1.1 app. It's working as advertised
I am working on a rails app. Installed Postgresql using postgresql-9.1.2-1-osx.dmg Installed pg gem.
I am currently working on a rails app where we are using mongoid/mongoDB on
I am working on a Rails 3.1.1 app that is using WICE_GRID and I
I'm working on a Rails app that existing users can invite additional members to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.