Q:

How to get a resource url in model

I have a simple posing app. How can I get a post url from it's model and pass it to Bitly shortener? (replace http://www.google.com with post url)
It's probably something like 
Rails.application.routes.url_helpers.posts_path(self...)

-
class TwitterWorker
  include Sidekiq::Worker

  def perform(title, url)
    tweet("#{title} #{url}")
  end
end

-
class Post < ActiveRecord::Base
  include Tweets
  extend FriendlyId

  after_create :post_to_twitter

.....

  private

  def post_to_twitter
    title = self.title[0..120]
    url = Bitly.client.shorten("http://www.google.com").short_url
    TwitterWorker.perform_async(title, url)
  end

end

-
I used to have this code in model
 # tweet("#{title[0..120]} #{ Bitly.client.shorten('http://www.google.com').short_url}") 

UP
I ended up doing the following. 
Since I have a few models that can make postings, I slightly refactored post_to_tweeter meth
worker
class TwitterWorker
  include Sidekiq::Worker
  include Tweets
  include Rails.application.routes.url_helpers

  def perform(message, slug)
    url = Bitly.client.shorten(post_url(slug, host: ActionMailer::Base.default_url_options[:host])).short_url
    tweet("#{message} #{url}")
  end
end

model
after_create :post_to_twitter

def post_to_twitter
  message = "#{self.title[0..120]}"
  TwitterWorker.perform_async(message, self.slug)
end

A:

you can include the url
helpers in models (though it
normally is not the best way of
dealing with things) 
class MyClass < ActiveRecord::Base
  include Rails.application.routes.   url_helpers
end

