parameterize user params like items, plus a cleaner parameterization scheme

This commit is contained in:
Emi Matchu 2011-07-26 18:49:52 -04:00
parent c592459d02
commit 033e71e9bf
3 changed files with 15 additions and 9 deletions

View file

@ -1,6 +1,8 @@
# requires item sweeper at bottom
class Item < ActiveRecord::Base
include PrettyParam
SwfAssetType = 'object'
has_many :closet_hangers
@ -173,15 +175,6 @@ class Item < ActiveRecord::Base
}
end
URL_CHAR_BLACKLIST = /[^a-z0-9\-]/i
def name_for_url
name.downcase.gsub(' ', '-').gsub(URL_CHAR_BLACKLIST, '')
end
def to_param
"#{id}-#{name_for_url}"
end
before_create do
self.sold_in_mall ||= false
true

View file

@ -0,0 +1,11 @@
module PrettyParam
BLACKLIST = /[^a-z0-9]/i
def name_for_param
name.split(BLACKLIST).select { |word| !word.blank? }.join('-')
end
def to_param
"#{id}-#{name_for_param}"
end
end

View file

@ -1,4 +1,6 @@
class User < ActiveRecord::Base
include PrettyParam
DefaultAuthServerId = 1
PreviewTopContributorsCount = 3