Module: SexyToParam::ClassMethods

Defined in:
lib/sexy_to_param.rb

Instance Method Summary collapse

Instance Method Details

#sexy_to_param(column = :slug) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sexy_to_param.rb', line 7

def sexy_to_param(column = :slug)
  define_method(:to_param) {
    if id
      slug = send(column)
      if slug.present?
        "%s-%s" % [id ,SexyToParam.escape(slug)]
      else
        id.to_s
      end
    end
  }
end