tracks/tracks/lib/url_friendly_name.rb
lukemelia aa41974d4c * Made links work for project and context links that contain an underscore('_') or a dot('.'). I removed urlize() and deurlize() in favor or methods on the models mixed in by the new UrlFriendlyName module.
* Removed tag_object() from application_helper as it was not being used.
* Introduced link_to_context() and link_to_project() helper methods.
* Fixed a javascript syntax error on the context page.



git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@373 a4c988fc-2ded-0310-b66e-134b36920a42
2006-12-11 04:48:56 +00:00

20 lines
No EOL
456 B
Ruby

module UrlFriendlyName
def self.included(base)
base.extend ClassMethods
end
def url_friendly_name
name.gsub(/_/,'__').gsub(/ /,'_').gsub(/\./,'__dot__')
end
module ClassMethods
def find_by_url_friendly_name(url_friendly_name)
name = url_friendly_name.gsub(/__dot__/,'.').gsub(/([^_])_(?!_)/,'\1 ').gsub(/__/,'_') #second regex replaces all single underscores with spaces
self.find_by_name(name)
end
end
end