help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
ruby-todo-list
/
app
/
models
RSK World
ruby-todo-list
Ruby Todo List - Task Management with User Authentication + Categories + Search + File Attachments + Email Notifications + Rails MVC + Modern Web Interface + API Integration + Educational Design
models
  • category.rb1.3 KB
  • task.rb2.4 KB
  • user.rb1023 B
category.rb
app/models/category.rb
Raw Download
Find: Go to:
# Ruby To-Do List Application - Category Model
# Created by: Molla Samser (help@rskworld.in, +91 93305 39277)
# Address: Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India, 713147
# Year: 2026

class Category < ApplicationRecord
  # Associations
  belongs_to :user
  has_many :tasks, dependent: :nullify

  # Validations
  validates :name, presence: true, length: { minimum: 1, maximum: 50 }
  validates :name, uniqueness: { scope: :user_id, case_sensitive: false }
  validates :color, presence: true, format: { with: /\A#[0-9a-fA-F]{6}\z/, message: "must be a valid hex color code" }

  # Default categories to create for new users
  DEFAULT_CATEGORIES = [
    { name: 'Work', color: '#007bff' },
    { name: 'Personal', color: '#28a745' },
    { name: 'Shopping', color: '#ffc107' },
    { name: 'Health', color: '#dc3545' },
    { name: 'Education', color: '#6f42c1' }
  ]

  # Methods
  def task_count
    tasks.count
  end

  def completed_task_count
    tasks.where(completed: true).count
  end

  def pending_task_count
    tasks.where(completed: false).count
  end

  # Class methods
  def self.create_defaults_for(user)
    DEFAULT_CATEGORIES.each do |category_attrs|
      user.categories.create!(category_attrs)
    end
  end
end
44 lines•1.3 KB
ruby

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer