mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-06 16:50:46 +08:00
If a poll is created with `dynamic-poll=true` then options can be amended after you post poll. This is useful for polls like: "favorite IDE" where you want people to easily be allowed to add options. --------- Co-authored-by: Martin Brennan <martin@discourse.org>
27 lines
627 B
Ruby
27 lines
627 B
Ruby
# 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 = self.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
|