Categories
Users can create categories to organize their resources (decks, etc.) with custom tags.
Models
Category (app/models/category.rb)
name– category name (required)user_id– optional owner; uniqueness scoped to user- Has many categorizations (dependent: destroy)
Categorization (app/models/categorization.rb)
- Polymorphic join table linking categories to any categorizable model
category_id,categorizable_type,categorizable_id- Uniqueness constraint on
(category_id, categorizable_type, categorizable_id)
Taggable Concern
Models include the Taggable concern to gain category support:
- Included in:
Deck tag_list– returns category names as an arraytag_list=– accepts array or JSON stringcategories_for_user– returns categories scoped to the current usertagged_with(tag_name)– scope for finding tagged records- On save,
set_categories_from_inputparses JSON fromtag_list_inputand finds or creates categories