From 033e71e9bfcf5ca746bb7106d5652ac449b35878 Mon Sep 17 00:00:00 2001 From: Matchu Date: Tue, 26 Jul 2011 18:49:52 -0400 Subject: [PATCH] parameterize user params like items, plus a cleaner parameterization scheme --- app/models/item.rb | 11 ++--------- app/models/pretty_param.rb | 11 +++++++++++ app/models/user.rb | 2 ++ 3 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 app/models/pretty_param.rb diff --git a/app/models/item.rb b/app/models/item.rb index 09d36126..ff025ad4 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -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 diff --git a/app/models/pretty_param.rb b/app/models/pretty_param.rb new file mode 100644 index 00000000..c24bd71a --- /dev/null +++ b/app/models/pretty_param.rb @@ -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 + diff --git a/app/models/user.rb b/app/models/user.rb index 20f027b4..b83b251c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,6 @@ class User < ActiveRecord::Base + include PrettyParam + DefaultAuthServerId = 1 PreviewTopContributorsCount = 3