Module: PrettyParam::ClassMethods

Defined in:
lib/pretty_param.rb

Instance Method Summary collapse

Instance Method Details

#has_pretty_param(*fields) ⇒ Object

Takes 1 or more symbols and stores them in class.pretty_params, and then overrides to_param



17
18
19
20
21
22
# File 'lib/pretty_param.rb', line 17

def has_pretty_param(*fields)			
	define_singleton_method :pretty_params, -> { fields }
	define_method :to_param do
		PrettyParam.escape("#{self.id}-#{self.class.pretty_params.map{|a| self.send(a.to_sym) }.join('-')}")
	end
end