0
我必須開發一個腳本,每小時發佈一條新聞更新(從我的數據庫獲取)到Facebook Fanpage。如何向Facebook發佈關於MVC模式的帖子?
我已經把這個放在控制器中,但我經常需要使用「Rails routes」,「Helper methos」和其他東西。 所以,如果我想尊重所有MVP模式,並保持清潔,我應該如何構建這一切?
@graph = Koala::Facebook::API.new(page_access_token)
@news.each do |n|
res = @graph.put_connections("PAGE_ID", "feed", {
:message => "Here I need to use an helper method",
:link => Rails.application.routes.url_helpers.news_url(n, :host => 'server.com'),
:picture => "Another helper method"
})
puts res
end
render :text => "Ok"
好吧,但在模型中,我可以使用resource_path和helpers方法嗎? – sparkle
使用它的問題是什麼?顯然你會用Rails創建一個依賴項,但是你仍然需要它。所以你可以創建一個私有方法並將其與Rails Helper一起使用。 –