Skip to content

Instantly share code, notes, and snippets.

@wfarr
Created October 18, 2008 05:05
Show Gist options
  • Save wfarr/17599 to your computer and use it in GitHub Desktop.
Save wfarr/17599 to your computer and use it in GitHub Desktop.
class Post
include DataMapper::Resource
property :id, Serial
property :title, String
property :content, Text
property :tags, String
property :slug, String
property :created_at, DateTime
property :updated_at, DateTime
has n, :comments
# has n, :tags
validates_present :title, :content
before :save, :set_slug
def to_html
red_cloth = RedCloth.new content
red_cloth.to_html
end
private
def set_slug(slug = self.title)
self.slug = slug.downcase.gsub(/[^a-z0-9- ]/, "").gsub(/[ ]+/, " ").gsub(" ", "-")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment