model snippets

How to generate URLs in your Rails model

Tagged to_uri, uri, routes, model  Languages ruby

You can use helpers in your model by first including them:

class Post < ActiveRecord::Base
  include ActionController::UrlWriter
  def to_uri

Some might consider this heresy, I don't. In my opinion it's similar to the to_param method. You could of course move it to a delegate class or something similar.