在Ruby on Rails中为帖子添加标签 [英] Adding tags to posts in Ruby on Rails

查看:63
本文介绍了在Ruby on Rails中为帖子添加标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用脚手架在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?

推荐答案

标记是如此普遍,以至于实现是一种商品.我相信作为可标记对象" 通常是实现标记的首选方法

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆