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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -