A short google search gives me the following:
http://henrik.nyh.se/2008/10/validating-slugs-against-existing-routes-in-rails
On rails 3, the method has moved to Rails.application.routes.recognize_path
So, I summarize:
class User < ActiveRecord::Base validates_format_of :name, :with => /\A[\w-]+\Z/ validates_uniqueness_of :name validate :name_is_not_a_route protected def name_is_not_a_route path = Rails.application.routes.recognize_path("/#{name}", :method => :get) rescue nil errors.add(:name, "conflicts with existing path (/#{name})") if path && !path[:username] end end
source share