Rails:如何使用after_commit方法传递帖子的URL

|| 我在弄清楚如何为每个用户帖子(在我的应用中称为supportposts)创建网址并将其传递给after_commit方法时遇到了一些麻烦。现在,我可以传递支持文章的属性,例如标题和内容,这些属性将共享给Twitter: supportpost.rb
after_commit :share_all

def share_all
 if user.authentications.where(:provider => \'twitter\').any?
 user.twitter_share(title, content)
 end
end
user.rb
def twitter_share(title, content) 
  twitter.update(\"#{title}, #{content}\")           #<--- this goes to twitter feed 
end
现在,我真正想做的就是在Twitter feed中共享supportpost的URL。我正在尝试像这样在模型外访问URL助手,但它弄乱了我的路线,并且出现了RoutingError(没有路线匹配{:action => \“ destroy \”,:controller => \“ supportposts \”} ) supportpost.rb
after_commit :share_all

Rails.application.routes.url_helpers.supportpost_url(@supportpost, :host => \'examplehost.com\') 

def share_all
if user.authentications.where(:provider => \'twitter\').any?
 user.twitter_share(supportpost_url)
 end
end
我在这里做错了什么?如何将URL正确传递到twitter_share? 这是我的路线和哨所管制员/模型http://pastie.org/1799492     
已邀请:
def share_all
  if user.authentications.where(:provider => \'twitter\').any?
    supportpost_url = Rails.application.routes.url_helpers.url_for :action => :show, :controller => \'supportposts\', :id => self, :host => \'example.com\'
    user.twitter_share(supportpost_url)
  end
end
Rails.application.routes.url_helpers.supportpost_url(@supportpost, :host => \'examplehost.com\')
那里没有任何好处。哦,顺便说一句,在此示例中,我使用了
url_for()
,但您可能也可以像在上面的问题中一样使用
supportpost_url()
。这里最主要的是您要在哪里调用该方法。 我希望这有帮助。     

要回复问题请先登录注册