Skip to content

Instantly share code, notes, and snippets.

@thetron
Created January 30, 2011 23:49
Show Gist options
  • Save thetron/803437 to your computer and use it in GitHub Desktop.
Save thetron/803437 to your computer and use it in GitHub Desktop.
# lib/active_record_ext.rb
module ActiveRecordExtensions
def self.included(base)
base.extend(ClassMethods)
end
# attempts to create an 'html-friendly' id
def to_html_param(include_class_name = true)
if include_class_name
"#{self.class.name.parameterize.underscore}_#{self.to_s.parameterize.underscore}"
else
self.to_s.parameterize.underscore
end
end
module ClassMethods
# nothing, at the moment
end
end
ActiveRecord::Base.send(:include, ActiveRecordExtensions)
# config/application.rb
# Make sure this is uncommented:
config.autoload_paths += %W(#{config.root}/lib)
# and add this below
require 'active_record_ext'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment