DEV Community

pbohea
pbohea

Posted on

Enum

class FollowRequest < ApplicationRecord
belongs_to :recipient, class_name: "User"
belongs_to :sender, class_name: "User"

enum :status, { pending: "pending", rejected: "rejected", accepted: "accepted" }
end

the "enum" enumerates a list of values that can be stored in the "status" column, allowing you to call the status on the model instance. example below

assume follow_request is a valid and pending

follow_request.accepted? # => false
follow_request.accepted! # sets status to "accepted" and saves

Top comments (0)