Skip to content

Instantly share code, notes, and snippets.

@qrush
Created September 20, 2008 16:58
Show Gist options
  • Save qrush/11772 to your computer and use it in GitHub Desktop.
Save qrush/11772 to your computer and use it in GitHub Desktop.
class Post < ActiveRecord::Base
belongs_to :user
belongs_to :category
validates_presence_of :title, :content, :user_id, :category_id
def to_param
"#{id}-#{title.slugify}"
end
end
class String
def slugify
self.gsub(/[^a-z0-9]+/i, '-').chomp('-')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment