discourse/plugins/poll/lib/post_extension.rb
Jarek Radosz 8baf4d5d4c
DEV: Enable Style/RedundantSelf rubocop rule (#40098)
(to be enabled in the shared config)
2026-05-19 19:27:45 +02:00

27 lines
622 B
Ruby
Vendored

# frozen_string_literal: true
module DiscoursePoll
module PostExtension
extend ActiveSupport::Concern
prepended do
attr_accessor :extracted_polls
has_many :polls, dependent: :destroy
after_save do
polls = extracted_polls
self.extracted_polls = nil
next if polls.blank? || !polls.is_a?(Hash)
post = self
::Poll.transaction do
polls.each { |name, poll| DiscoursePoll::Poll.create!(post.id, poll) }
post.custom_fields[DiscoursePoll::HAS_POLLS] = true
post.save_custom_fields(true)
end
end
end
end
end