简体   繁体   中英

FriendlyID with globalize

My Post model uses translates method from globalize gem and friendly_id to gerenate more user friendly urls.

When I create my post in my native language it gets added. Accessing it after switching to en locale makes it fallback for the native translation, as it does not have any. How can I achieve this with friendlyID ? I mean, the slug for current locale is generated correctly, but it is still nil for the other locales.

class Post < ApplicationRecord
    # Translations
    translates :title, :body, :slug
    # FriendlyID
    extend FriendlyId
    friendly_id :title, use: :slugged
end

尝试将globalize添加到friendly_id

friendly_id :title, :use => [:slugged, :globalize]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM