DEV: Fix poll plugin causing error when server reloads in dev env.
This commit is contained in:
parent
d8d54a92f1
commit
6359a5f8a9
|
@ -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|
|
||||
|
|
Loading…
Reference in New Issue