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 array
  • tag_list= – accepts array or JSON string
  • categories_for_user – returns categories scoped to the current user
  • tagged_with(tag_name) – scope for finding tagged records
  • On save, set_categories_from_input parses JSON from tag_list_input and finds or creates categories

This site uses Just the Docs, a documentation theme for Jekyll.