Module: Motr::Mods::Sluggable
- Extended by:
- Motr::Modding
- Defined in:
- lib/motr/mods/sluggable.rb
Overview
Sluggable generates a url-friendly “slug” from a particular attribute.
Instance Method Summary collapse
Methods included from Motr::Modding
append_features, apply, configure, options
Instance Method Details
#_create_slugged_fields ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/motr/mods/sluggable.rb', line 27 def _create_slugged_fields slug_opts = self.class. slug_fields = slug_opts[:fields] slug_as = [slug_opts[:as]].flatten [slug_fields].flatten.map(&:to_sym).each_with_index do |atr, i| next if self.send(atr).nil? unless slug_as.empty? || slug_as[i].nil? self.send(:"#{slug_as[i]}=", self.send(atr).to_slug) else self.send(:"#{atr.to_s}=", self.send(atr).to_slug) end end end |