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?
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- HTML form is not sending $_POST values
- Eager-loading association count with Arel (Rails 3
- POST Base64 encoded data in PHP
相关文章
- 请大神帮忙 post向https接口发送数据 部署到服务器为什么运行一会后就会报空指针
- WCF发布Windows服务 POST方式报错 GET方式没有问题 应该怎么解决?
- 用 $.ajax POST 请求数据报错
- 设备发送一个http post请求,接收不到
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
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.
Err, the usual way? Add Tag entity, add
has_many :tags
in your Post entity. Then migrate. That would be all.I would suggest creating a Tag model and using
has_and_belongs_to_many
to assign tags to posts. I don't know if the scaffold feature will help you create a form for that, but it shouldn't be difficult to add it yourself. I also suggest using the formtastic plugin as it's much easier and nicer to create forms with it.