我正在使用omniauth
和delayed_job
的组合来与Facebook整合。我有一个Authentication
模型看起来有点像这样:
class Authentication < ActiveRecord::Base
def account
@account ||= FbGraph::User.me(token)
end
def post_to!(opts = {})
account.feed!(opts)
end
end
然后从控制台我可以做到这样的事情:
auth.post_to :message => 'Foo bar', :link => 'http://google.com'
...一切正常,更新发布到我的Facebook Feed。
但是,在应用程序中,我创建了一个完全按照上述方式执行的自定义延迟作业,只有每次都出现以下错误堆栈时才会失败:
undefined method `bytesize'' for nil:NilClass
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/activesupport-3.1.3/lib/active_support/whiny_nil.rb:48:in `method_missing''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/httpclient-2.2.4/lib/httpclient/http.rb:830:in `block in escape''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/activesupport-3.1.3/lib/active_support/core_ext/string/output_safety.rb:142:in `gsub''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/activesupport-3.1.3/lib/active_support/core_ext/string/output_safety.rb:142:in `gsub''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/httpclient-2.2.4/lib/httpclient/http.rb:829:in `escape''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/httpclient-2.2.4/lib/httpclient/http.rb:822:in `block in escape_query''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/httpclient-2.2.4/lib/httpclient/http.rb:818:in `each''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/httpclient-2.2.4/lib/httpclient/http.rb:818:in `collect''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/httpclient-2.2.4/lib/httpclient/http.rb:818:in `escape_query''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/httpclient-2.2.4/lib/httpclient/http.rb:809:in `create_query_part_str''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/httpclient-2.2.4/lib/httpclient/http.rb:538:in `set_content''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/httpclient-2.2.4/lib/httpclient/http.rb:447:in `init_request''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/httpclient-2.2.4/lib/httpclient/http.rb:705:in `new_request''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/httpclient-2.2.4/lib/httpclient.rb:997:in `create_request''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/httpclient-2.2.4/lib/httpclient.rb:866:in `do_request''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/httpclient-2.2.4/lib/httpclient.rb:756:in `request''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/httpclient-2.2.4/lib/httpclient.rb:666:in `post''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/fb_graph-2.4.7/lib/fb_graph/node.rb:55:in `block in post''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/fb_graph-2.4.7/lib/fb_graph/node.rb:122:in `handle_response''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/fb_graph-2.4.7/lib/fb_graph/node.rb:54:in `post''
/Users/aaron/.rvm/gems/ruby-1.9.2-p290@bb/gems/fb_graph-2.4.7/lib/fb_graph/connections/feed.rb:15:in `feed!''
/Users/aaron/Sites/bb/app/models/authentication.rb:40:in `post_to!''
/Users/aaron/Sites/bb/lib/share_activity_job.rb:39:in `block in perform''
/Users/aaron/Sites/bb/lib/share_activity_job.rb:11:in `each''
/Users/aaron/Sites/bb/lib/share_activity_job.rb:11:in `perform''
我已经正式开始将昂贵的计算机扔出窗外。任何人都可以提供任何关于它失败的原因,为什么它在从控制台执行时有效,但在从自定义delayed_job执行时失败?
非常感谢任何帮助。谢谢。
答案 0 :(得分:1)
解决方案很简单。 您必须在代码中使用 to_str :
auth.post_to message: message.to_str, link: 'http://google.com'