10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/active_record/acts/acts_as_sluggy.rb', line 10
def has_slug(options = {})
configuration = {:attribute => "title", :to_param => "slug", :to_url => "parameterize"}
configuration.update(options) if options.is_a?(Hash)
before_save :update_slug
to_param = case configuration[:to_param]
when :id_slug
"id.to_s + '-' + slug"
else
configuration[:to_param]
end
class_eval <<-EOV
def to_param
#{to_param}
end
def update_slug
self.slug = self.#{configuration[:attribute]}.#{configuration[:to_url]}
end
EOV
end
|