DEV: Fix poll plugin causing error when server reloads in dev env.

This commit is contained in:
Guo Xiang Tan 2020-05-08 14:58:39 +08:00
parent d8d54a92f1
commit 6359a5f8a9
No known key found for this signature in database
GPG Key ID: FBD110179AAC1F20
1 changed files with 17 additions and 15 deletions

View File

@ -451,28 +451,30 @@ after_initialize do
mount ::DiscoursePoll::Engine, at: "/polls"
end
Post.class_eval do
attr_accessor :extracted_polls
reloadable_patch do
Post.class_eval do
attr_accessor :extracted_polls
has_many :polls, dependent: :destroy
has_many :polls, dependent: :destroy
after_save do
polls = self.extracted_polls
next if polls.blank? || !polls.is_a?(Hash)
post = self
after_save do
polls = self.extracted_polls
next if polls.blank? || !polls.is_a?(Hash)
post = self
Poll.transaction do
polls.values.each do |poll|
DiscoursePoll::Poll.create!(post.id, poll)
Poll.transaction do
polls.values.each do |poll|
DiscoursePoll::Poll.create!(post.id, poll)
end
post.custom_fields[DiscoursePoll::HAS_POLLS] = true
post.save_custom_fields(true)
end
post.custom_fields[DiscoursePoll::HAS_POLLS] = true
post.save_custom_fields(true)
end
end
end
User.class_eval do
has_many :poll_votes, dependent: :delete_all
User.class_eval do
has_many :poll_votes, dependent: :delete_all
end
end
validate(:post, :validate_polls) do |force = nil|