Here is a user class example with a method to create a URL ready slug.

class User < ActiveRecord::Base
 
  def display_name
    user_display_name || "#{first_name} #{last_name}"
  end
 
  def create_slug
    self.slug = self.display_name.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
  end
end

:)

Leave a Reply

Your email address will not be published. Required fields are marked *