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

  • SEARCH
  • Home
  • 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 9176077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:01:20+00:00 2026-06-17T17:01:20+00:00

With the koala gem I am trying to count checkins for a page. I

  • 0

With the koala gem I am trying to count checkins for a page. I am using rails.

In my user.rb I have a method for getting a new connection to the Facebook graph:

class User < ActiveRecord::Base
 def facebook
     @facebook ||= Koala::Facebook::API.new(oauth_token)
 end
end

In my school.rb I have a method for counting the checkins:

class school < ActiveRecord::Base
 def count_checkins(name)
  checkins = @facebook.fql_query("SELECT checkins FROM page WHERE name = #{name}")
 end
end

And I am calling it from the view like this:

<%= @school.count_checkins(@school.name) %>

But I get the following error:

undefined method `fql_query' for nil:NilClass

Dont really understand why I get this error, any help would be wonderful.

  • 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-17T17:01:21+00:00Added an answer on June 17, 2026 at 5:01 pm

    It looks like you haven’t actually created the @facebook object inside your School model. We’d need to see the rest of your school.rb file to know for sure. I’d suggest you create the object inside your School.initialize() method like so:

    def initialize(oauth_token)
      unless oauth_token.nil?
        @facebook = Koala::facebook::API.new(oauth_token)
      end
    end
    

    In order for this to work, you’ll need to pass the desired oauth_token to your School.new() call. Then you’ll have one @facebook object for each School.

    Edit

    After looking at the gist, I realized that you had actually intantiated a User object, and called the facebook method on that. That is actually the better way to do it. The problem is, you’re using @current_user, which would have to be setup as a property of the school model. You probably meant to use the helper function current_user instead.

     def count_checkins(name)
      u = current_user
      u.@facebook.fql_query("SELECT checkins FROM page WHERE name = #{name}")
     end
    

    Try that and see what happens. At the very least, you should get a different error message.

    Edit 2

    So, now I’m thinking the current_user function should be called in controller code, not model code. This is because the current user is something that doesn’t really exist except as part of an active request. Therefore, we should take User u as a parameter to the count_checkins function like so:

    def count_checkins(name, u)
      u.facebook.fql_query("SELECT checkins FROM page WHERE name = #{name}")
    end
    

    You’ll need to change the code where you call count_checkins() too:

    count_checkins(name, current_user)
    

    That should do it. Let’s see!

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

Sidebar

Related Questions

I am using the Koala gem to make facebook requests and i have the
I'm using the Koala gem in a Rails 3.2 app. I'm trying to post
The application is written in Ruby on Rails, using Koala GEM to support Facebook
I am having a rails app and using the Koala gem for the Facebook
I am working on rails 3 app and using the koala gem to get
How do I post to a user page using Koala? I don't want to
I'm trying to learn the koala gem to link Facebook with my Ruby on
Currently, im using ruby gem Koala and can get a list of user friends,
I am trying to add an app request from a user using Koala/Omniauth @graph
I'm using ruby, sinatra, and the koala gem to create an app for facebook.

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.