在 Ruby on Rails 中为帖子添加标签 [英] Adding tags to posts in Ruby on Rails
问题描述
我正在使用 Scaffolding 在 Rails 中创建一个博客.我想在每个帖子上添加一个标签"字段,就像在 StackOverflow 和 WordPress 上一样.我可以使用字符串类型( rails generate scaffold post title:string body:text tags:string
)然后用逗号分隔,但这不是一个好习惯,因为我希望读者按标签浏览(例如 /tags/web20
或 /tags/lol
).我该怎么做?
I am creating a blog in Rails using Scaffolding. I want to add a 'tags' field on each post like on StackOverflow and WordPress. I can do this with the string type ( rails generate scaffold post title:string body:text tags:string
) and then comma separated, but it's not good practice since I want the reader to browse by tags ( e.g. /tags/web20
or /tags/lol
). How can I do this?
推荐答案
标记是如此普遍以至于实现是一种商品.我相信 "acts as taggable on" 通常是实现标签的首选方式.
Tagging is so common that implementations are a commodity. I believe "acts as taggable on" is usually the preferred way of implementing tags.
在此处查看其他流行的解决方案.
See other popular solutions here.
如果你想自己实现它,你可以深入源代码寻找一些想法.
If you wish to implement it yourself, you could dive into the source code to find some ideas.
这篇关于在 Ruby on Rails 中为帖子添加标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!