我修補我的方法來創建一個耙子任務,抓取給定頁面的簽入量扔臉譜。我使用考拉寶石和鐵軌。Rake任務 - 未定義的方法
我這樣做是通過創建一個rake任務:
task :get_likes => :environment do
require 'koala'
# Grab the first user in the database
user = User.first
# Loop throw every school & and call count_checkins
School.columns.each do |column|
user.facebook.count_checkins(column.name, user)
end
end
# Count like for every school else return 0
def count_checkins(name, u)
a = u.facebook.fql_query('SELECT checkins FROM page WHERE name = "' + name + '"')
if a[0].nil?
return 0
else
return b = a[0]["checkins"]
end
end
# Initialize an connection to the facebook graph
def facebook
@facebook ||= Koala::Facebook::API.new(oauth_token)
end
但我得到一個錯誤:
private method `count_checkins' called for #<Koala::Facebook::API:0x007fae5bd348f0>
任何意見或更好的方式來編寫一個rake任務將是真棒!
檢查完整的錯誤在這裏:https://gist.github.com/shuma/4949213
最後2個方法定義在哪裏? – 2013-02-13 23:16:38
@ mind.blank在rake文件中。 – SHUMAcupcake 2013-02-13 23:19:53
您需要在相關的類定義中定義它們。例如'user.facebook'將嘗試調用User類的'facebook'方法,但是您定義的方法不附加到該類。 – 2013-02-13 23:22:11