friendly id - Rails :: Generate slugs with FriendlyId, Globalize and slug_candidates -
i building rails application , stuck when generating slug article second locale defined.
main locale (french), checked if article have title , if it’s case add integer (id) @ end second locale (english) it’s generate slug without checking if article exists (which give me duplicated slugs).
here model:
class post < activerecord::base translates :title, :slug, :content, fallbacks_for_empty_translations: true active_admin_translates :title, :slug, :content, fallbacks_for_empty_translations: true extend friendlyid friendly_id :slug_candidates, use: [:slugged, :globalize, :finders] private def slug_candidates [:title, [:title, :deduced_id]] # works main locale not others end def deduced_id self.class.where(title: title).count + 1 end end
how can id added slug secondary locales when article exists same title ?
thanks !
my project:
- rails 4.2.6
- activeadmin 1.0.0.pre2
- globalize 5.0.1
- friendlyid 5.1.0
- friendlyid-globalize 1.0.0.alpha2
i working updating slug_candidates method this:
def slug_candidates [[:title, :deduced_id]] end
Comments
Post a Comment