tabletop-companion/app/models/dice_roll.rb

20 lines
579 B
Ruby
Raw Normal View History

2024-06-13 07:41:45 +00:00
# frozen_string_literal: true
class DiceRoll < ApplicationRecord
belongs_to :rollable, polymorphic: true
belongs_to :table
validates :result, presence: true,
numericality: { only_integer: true }
2024-06-13 12:24:54 +00:00
2024-06-13 16:04:25 +00:00
after_create_commit do
broadcast_append_to table, target: "events"
2024-06-14 07:39:38 +00:00
broadcast_append_to table, target: "table-notifications",
partial: "shared/notification", locals: { object: self }
2024-06-13 16:04:25 +00:00
end
2024-06-13 12:24:54 +00:00
def display_text
"#{rollable.character.name} rolled #{rollable.name}: <strong>#{result}</strong>".html_safe
end
2024-06-13 07:41:45 +00:00
end