带点的漂亮网址(Friendly_id gem)

发布于 2024-12-07 12:05:33 字数 82 浏览 3 评论 0原文

许多解决方案适用于 Rails 2,但没有适用于 Rails 3.1,因为地图对象已被删除。

最新的rails中这个问题有解决方案吗?

Many solutions are available for rails 2 but none for rails 3.1 because the map object has been removed.

Any solution for this problem in the latest rails?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜`诱少女 2024-12-14 12:05:33

我最近不得不在一个项目中这样做。幸运的是,在每个模型的基础上重写 slug 生成方法很简单。

请参考

https://github.com/诺曼/Friendly_id/blob/master/lib/Friendly_id/slugged.rb#L113-116

https://github.com/norman/friend_id/blob /master/lib/Friendly_id/slugged.rb#L227-231

您应该能够在模型上定义它:

# Use default slug, but upper case and with underscores
def normalize_friendly_id(string)
  super.upcase.gsub("-", ".")
end

希望这会有所帮助。

注意:此方法在FriendlyId 3.x中也可用。它非常适合定义用于生成 slug 字符串的自定义正则表达式。

I have had to do this recently on a project. Luckily, it's simple to override the slug-generating method on a per-model basis.

please refer to

https://github.com/norman/friendly_id/blob/master/lib/friendly_id/slugged.rb#L113-116

and

https://github.com/norman/friendly_id/blob/master/lib/friendly_id/slugged.rb#L227-231

you should be able to define this on the model:

# Use default slug, but upper case and with underscores
def normalize_friendly_id(string)
  super.upcase.gsub("-", ".")
end

Hope this helps.

Note: This method is available in FriendlyId 3.x as well. It's great for defining a custom regex for generating slug strings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文