Validate the number of has_many items in Ruby on Rails
A better solution has been provided by @SooDesuNe on this SO post validates :tags, length: { minimum: 1, maximum: 6 }
A better solution has been provided by @SooDesuNe on this SO post validates :tags, length: { minimum: 1, maximum: 6 }
I believe you’ll find interesting this blog post: Tags: Database schemas The Problem: You want to have a database schema where you can tag a bookmark (or a blog post or whatever) with as many tags as you want. Later then, you want to run queries to constrain the bookmarks to a union or intersection … Read more
One item is going to have many tags. And one tag will belong to many items. This implies to me that you’ll quite possibly need an intermediary table to overcome the many-to-many obstacle. Something like: Table: Items Columns: Item_ID, Item_Title, Content Table: Tags Columns: Tag_ID, Tag_Title Table: Items_Tags Columns: Item_ID, Tag_ID It might be that … Read more
Here is a solution with alphabetically sorted tags on a single page. It uses Liquid only, which means that it works on GitHub Pages: {% capture tags %} {% for tag in site.tags %} {{ tag[0] }} {% endfor %} {% endcapture %} {% assign sortedtags = tags | split:’ ‘ | sort %} {% … Read more
Here’s a good article on tagging Database schemas: http://howto.philippkeller.com/2005/04/24/Tags-Database-schemas/ along with performance tests: http://howto.philippkeller.com/2005/06/19/Tagsystems-performance-tests/ Note that the conclusions there are very specific to MySQL, which (at least in 2005 at the time that was written) had very poor full text indexing characteristics.
Three tables (one for storing all items, one for all tags, and one for the relation between the two), properly indexed, with foreign keys set running on a proper database, should work well and scale properly. Table: Item Columns: ItemID, Title, Content Table: Tag Columns: TagID, Title Table: ItemTag Columns: ItemID, TagID