gpt4 book ai didi

ruby-on-rails - Ruby on Rails friendly_id、babosa gems、音译问题

转载 作者:太空宇宙 更新时间:2023-11-03 16:45:03 25 4
gpt4 key购买 nike

我正在使用 gem :friendly_id, babosa

模型product.rb:

class Product < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: [:slugged, :finders]
has_many :tags

def normalize_friendly_id(input)
input.to_s.to_slug.normalize(transliterations: :russian).to_s
end

end

我启动了 сonsole,为现有产品生成 slug:

Product.find_each(&:save)

检查最后一项:

Product.last

#<Product id: 4972, name: "ВА 47-63, 2P 2А (C) EKF", created_at: "2016-01-27 11:32:39", updated_at: "2016-01-27 11:32:39", slug: 04b4aa2d-2bb9-46f9-8d49-cbb9d0c3f872">

但是音译是错误的。我正在尝试在控制台中做同样的事情:

"ВА 47-63, 2P 2А (C) EKF".to_s.to_slug.normalize(transliterations: :russian).to_s
=> "va-47-63-2p-2a-c-ekf"

现在是正常结果。我不明白为什么会这样。

以同样的方式对标签进行音译,她收到了足够的。

模型tag.rb:

class Tag < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: [:slugged, :finders]
belongs_to :product

def normalize_friendly_id(input)
input.to_s.to_slug.normalize(transliterations: :russian).to_s
end
end

最佳答案

您可以通过替换模型 product.rb 上的函数来修复它:

"input.to_s.to_slug.normalize(transliterations: :russian).to_s" ->
"input.to_slug.normalize! :transliterations => [:russian]"

在我的模型上是:

def normalize_friendly_id(text)
text.to_slug.normalize! :transliterations => [:vietnamese]
end

关于ruby-on-rails - Ruby on Rails friendly_id、babosa gems、音译问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35037834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com