Rails friendly id with non-Latin characters

后端 未结 2 467
花落未央
花落未央 2021-01-19 17:39

I have a model which I use its friendly id as slug:

extend FriendlyId
friendly_id :slug_candidates, :use => :scoped, :scope => :account

def slug_candi         


        
2条回答
  •  失恋的感觉
    2021-01-19 18:30

    There's a Rails API method for that transliterate

    Example use:

    transliterate('Ãrøskøbing')
    # => "AEroskobing"
    

    By default it only supports latin-based languages and Russian but you should be able to find rules for other alphabets as well (as explained in the linked doc)

    EDIT
    To achieve the same behaviour as wordpress you can simply use url encoding, as in example below

    URI::encode('שלום') => "%D7%A9%D7%9C%D7%95%D7%9D"
    

提交回复
热议问题