# Question Answer Plugin

**URL:** https://meta.discourse.org/t/question-answer-plugin/56032
**Category:** Plugin
**Tags:** deprecated
**Created:** [January 19, 2017, 4:43pm UTC](https://meta.discourse.org/t/question-answer-plugin/56032 "2017-01-19T16:43:47Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![Pad\_Pors](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pad_pors/32/52016_2.png) [@Pad\_Pors](https://meta.discourse.org/u/Pad_Pors)
#### Post date: [March 15, 2017, 7:33am UTC](https://meta.discourse.org/t/question-answer-plugin/56032/24 "2017-03-15T07:33:48Z")

</div>

some minor issues with the QA plugin-test:

- answers are not sorted based on their votes in our Persian forum. in fact they become randomly sorted after activation of QA tag. and won’t go back to the previous time-based sorting if I deactivate the tag from the topic ☹

- people can vote to their own reply.

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [April 4, 2017, 12:50pm UTC](https://meta.discourse.org/t/question-answer-plugin/56032/25 "2017-04-04T12:50:32Z")

</div>

Hey dude, sorry for being unresponsive here. Will take a look soon.

---

<div class="post-metadata">

### Author: ![TomekB](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tomekb/32/66593_2.png) [@TomekB](https://meta.discourse.org/u/TomekB)
#### Post date: [May 2, 2017, 8:01am UTC](https://meta.discourse.org/t/question-answer-plugin/56032/26 "2017-05-02T08:01:17Z")

</div>

@angus did you manage to solve this?

On my forum this is also an issue, posts are not sorted based on their votes, this is an example:

> **[dobreprogramy - strona główna](https://www.dobreprogramy.pl/)**
>
> Największy polski serwis o nowych technologiach - aktualności, oprogramowanie, publikacje, demonstracje, wideo, testy s…

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [May 3, 2017, 1:14am UTC](https://meta.discourse.org/t/question-answer-plugin/56032/27 "2017-05-03T01:14:36Z")

</div>

Ok, previously I was trying to be clever and use the existing `sort_order` property on posts, however it seems that that breaks down when the topic gets longer than a handful of posts. I’ve just directly overridden the sort order of topics which are in a QA enabled category. So it’ll work for topics of any length.

[https://github.com/angusmcleod/discourse-qa/commit/0a5521c3e0322ae1de99b05c287ba076990d8f1d](https://github.com/angusmcleod/discourse-qa/commit/0a5521c3e0322ae1de99b05c287ba076990d8f1d)

cc @Pad_Pors @TomekB

---

<div class="post-metadata">

### Author: ![Alex\_Reguyal](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@Alex\_Reguyal](https://meta.discourse.org/u/Alex_Reguyal)
#### Post date: [May 3, 2017, 3:16am UTC](https://meta.discourse.org/t/question-answer-plugin/56032/28 "2017-05-03T03:16:15Z")

</div>

I tried to move a Q&A topic from the QA category to a different category, and all the votes and voting functionality disappeared. So I added a “question” tag to the topic, and all the votes came back on again. So the tag actually works.

The bug that I encountered is that, you can “like” any and all replies as long as you haven’t voted yet. However, if you vote first, then you can’t like anymore, you will get this error – “You are not permitted to view the requested resource”. So you should first undo your vote, then like some of the replies, then cast your precious one vote again.

---

<div class="post-metadata">

### Author: ![Lincoln](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lincoln/32/71605_2.png) [@Lincoln](https://meta.discourse.org/u/Lincoln)
#### Post date: [May 3, 2017, 7:36am UTC](https://meta.discourse.org/t/question-answer-plugin/56032/29 "2017-05-03T07:36:50Z")

</div>

Thanks for sharing 🙂

---

<div class="post-metadata">

### Author: ![TomekB](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tomekb/32/66593_2.png) [@TomekB](https://meta.discourse.org/u/TomekB)
#### Post date: [May 4, 2017, 11:08am UTC](https://meta.discourse.org/t/question-answer-plugin/56032/30 "2017-05-04T11:08:29Z")

</div>

@angus After installing your plugin I cannot read any private messages.

I get an error and this log message:

```
NoMethodError (undefined method custom_fields for nil:NilClass)
/var/www/discourse/plugins/discourse-qa/plugin.rb:66:in qa_enabled

```

---

<div class="post-metadata">

### Author: ![DiscourseMetrics](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discoursemetrics/32/55756_2.png) [@DiscourseMetrics](https://meta.discourse.org/u/DiscourseMetrics)
#### Post date: [May 4, 2017, 12:21pm UTC](https://meta.discourse.org/t/question-answer-plugin/56032/31 "2017-05-04T12:21:20Z")

</div>

I have the same issue. Strangely it persists when entering discourse’s [safe mode](https://meta.discourse.org/t/53504?silent=true).

---

<div class="post-metadata">

### Author: ![DiscourseMetrics](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discoursemetrics/32/55756_2.png) [@DiscourseMetrics](https://meta.discourse.org/u/DiscourseMetrics)
#### Post date: [May 4, 2017, 6:15pm UTC](https://meta.discourse.org/t/question-answer-plugin/56032/32 "2017-05-04T18:15:50Z")

</div>

> [@DiscourseMetrics.com](#):
>
> Strangely it persists when entering discourse’s [safe mode](https://meta.discourse.org/t/53504?silent=true).

Found the reason: “[Safe mode](https://meta.discourse.org/t/53504?silent=true) currently only disable the JavaScript portions of plugins”

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [May 5, 2017, 11:00pm UTC](https://meta.discourse.org/t/question-answer-plugin/56032/33 "2017-05-05T23:00:44Z")

</div>

Yup, looks like my last update didn’t handle the case of uncategorized topics. Please give it another shot.

[https://github.com/angusmcleod/discourse-qa/commit/a64544c6682639eff413333de129f137d9994e23](https://github.com/angusmcleod/discourse-qa/commit/a64544c6682639eff413333de129f137d9994e23)

cc @DiscourseMetrics.com

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [May 5, 2017, 11:20pm UTC](https://meta.discourse.org/t/question-answer-plugin/56032/34 "2017-05-05T23:20:41Z")

</div>

This bug is now fixed as well.

[https://github.com/angusmcleod/discourse-qa/commit/99fbb0fbcad909073294e4ba25d4c31125b99939](https://github.com/angusmcleod/discourse-qa/commit/99fbb0fbcad909073294e4ba25d4c31125b99939)

---

<div class="post-metadata">

### Author: ![stantyan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stantyan/32/121024_2.png) [@stantyan](https://meta.discourse.org/u/stantyan)
#### Post date: [May 9, 2017, 10:09am UTC](https://meta.discourse.org/t/question-answer-plugin/56032/35 "2017-05-09T10:09:23Z")

</div>

Hi @angus, thank you for a great plugin.

However, I’m curious how this plugin works with built-in posts timeline. If “this plugin re-arranges the posts in the topic based on those that have been supported” then this timeline is messed up, isn’t it? Posts with the most votes will be on top no matter when they were posted.

Or this plugin turns off the timeline and default chronological posts order?

Your example topic [https://dev.civll.com/t/testing-the-qa-plugin/187](https://dev.civll.com/t/testing-the-qa-plugin/187) does not work.

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [May 15, 2017, 3:31am UTC](https://meta.discourse.org/t/question-answer-plugin/56032/36 "2017-05-15T03:31:30Z")

</div>

Sorry for the slow reply, I’ve been on holiday 🌞 🐻

> [@stantyan](#):
>
> However, I’m curious how this plugin works with built-in posts timeline. If “this plugin re-arranges the posts in the topic based on those that have been supported” then this timeline is messed up, isn’t it? Posts with the most votes will be on top no matter when they were posted.

Yes indeed. The timeline no longer ‘works’ if you use this plugin. I haven’t explicitly addressed that yet. But you’re right that this needs it. I’ll add something in the next few days to deal with it properly. You could always hide it with CSS if need be.

I haven’t needed to address this for my own purposes, as I’m using this in conjunction with my layouts plugin (and others).

Basically, how this plugin works is that it:

1. Uses the latent `vote` post action in the core Discourse code and stores the votes in the latent `vote_count` property of posts. These properties both already exist in the core code, but are not used in the client at the moment (see e.g. [here](https://github.com/discourse/discourse/blob/master/app/models/post.rb#L724)). There’s even [core logic](https://github.com/discourse/discourse/blob/55b61e9bea102a52dc3158343ce2c289aace74d2/app/models/post_action.rb#L437) to re-arrange the `sort_order` of the topic based on the `vote_count`, but it doesn’t work anymore (or maybe I don’t understand it). Previously I had tried to use that, but that led to the issues discussed above, so I added 2…

2. Overrides the default topic view ordering logic for topics in categories with the appropriate flag, to order posts by `vote_count` instead of by ` post_number` (the normal way topic views are ordered) ([see here](https://github.com/angusmcleod/discourse-qa/blob/master/plugin.rb#L63)). If you want to understand the post ordering logic for topics, most of it is in `lib/topic_view.rb`. Tantalizingly, there’s a [reference in the code](https://github.com/discourse/discourse/blob/master/lib/topic_view.rb#L318) to allowing custom post orders in the future

Basically, this ordering logic boils down to [this SQL statement](https://github.com/angusmcleod/discourse-qa/blob/master/plugin.rb#L70):

`case when post_number = 1 then 0 else 1 end, vote_count DESC`

i.e. if the post is the first post in the topic, then put it at the top, otherwise order the topic by post vote count.

I’ve made [another Q/A topic](https://dev.civll.com/t/whats-the-best-way-to-help-out/27) on my dev instance if you want to take a look. Or you could sign up an account and create your own.

---

<div class="post-metadata">

### Author: ![stantyan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stantyan/32/121024_2.png) [@stantyan](https://meta.discourse.org/u/stantyan)
#### Post date: [May 15, 2017, 7:30am UTC](https://meta.discourse.org/t/question-answer-plugin/56032/37 "2017-05-15T07:30:58Z")

</div>

Thank you so much for such a detailed answer!

1. Do you think this plugin could possibly significantly slow down page load speed? if there are lot’s of posts in a topic.

2. Also, is there any possibility that this plugin will conflict with future discourse developments and updates. For example, if t hey decided to roll out their own “posts up-voting” feature.

3. And the last one, is there any was to turn your plugin active site-wide in all categories? I have about 100 categories, and going to each category settings to turn on the plugin is PITA 🙂

4. As far as I understood, vote counts of each post are saved in a database and remain there even if I remove this plugin, is this correct? And if yes, could it possibly cause some issues in future discourse updates?

Thank you so much again for this plugin.

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [May 16, 2017, 10:05pm UTC](https://meta.discourse.org/t/question-answer-plugin/56032/38 "2017-05-16T22:05:50Z")

</div>

> [@stantyan](#):
>
> Do you think this plugin could possibly significantly slow down page load speed? if there are lot’s of posts in a topic.

No, it won’t affect page load speed.

> [@stantyan](#):
>
> Also, is there any possibility that this plugin will conflict with future discourse developments and updates. For example, if t hey decided to roll out their own “posts up-voting” feature.

Yes, this is a possibility with any plugin. If Discourse releases a core mechanism for up-voting posts then I will discontinue work on this and use that instead of this.

> [@stantyan](#):
>
> And the last one, is there any was to turn your plugin active site-wide in all categories? I have about 100 categories, and going to each category settings to turn on the plugin is PITA

No, there isn’t yet. I could add this, but I strongly suggest you test this in a single category first, for at least a few weeks. This is a new plugin. I don’t use it in production myself yet.

[quote=“stantyan, post:37, topic:56032”]  
As far as I understood, vote counts of each post are saved in a database and remain there even if I remove this plugin, is this correct?[/quote]

Correct.

> [@stantyan](#):
>
> And if yes, could it possibly cause some issues in future discourse updates?

The main question here is whether a future Discourse version will use the existing `vote_count` property of posts. If it does, then all votes made with this plugin will be picked up by the new core functionality.

Remember that `vote_count` is a property in the core Discourse code itself. It’s been there since the [initial release](https://github.com/discourse/discourse/blob/5dbd6a304bed5400be481d71061d3e3ebb4d6785/db/migrate/20120924182031_add_vote_count_to_posts.rb) of Discourse, i.e. 2013.

The alternative way of handling the storage of votes would have been to create a post custom field, i.e. `post.custom_fields['vote_count']`. The reason I chose not to do this was because it seemed redundant given there was an existing post property, and it would also make it harder to migrate the data created by this plugin if the core `vote_count` field were used in the future for a similar purpose. Also, I would have to re-create the front-end post-action UI and translations that already exist for voting.

I suppose there is a risk that `vote_count` could be used in the future in a such a way that does not conceptually relate to the way I am using it here, however I doubt it. Something called `vote_count` on a post object could only really be used for storing the count of how many people have voted for that post.

If you’re wondering whether this plugin conflicts with the [poll plugin](https://github.com/discourse/discourse/tree/master/plugins/poll) or the [topic voting plugin](https://meta.discourse.org/t/discourse-voting/40121), it doesn’t. Those plugins use different fields. All are about voting, but different kinds of voting…

 ![image](https://global.discourse-cdn.com/meta/original/3X/2/4/2476c7081e17ec668e19af3baa27fd661ac7f912.gif)

---

<div class="post-metadata">

### Author: ![jwermers](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@jwermers](https://meta.discourse.org/u/jwermers)
#### Post date: [August 8, 2017, 8:15pm UTC](https://meta.discourse.org/t/question-answer-plugin/56032/41 "2017-08-08T20:15:05Z")

</div>

@angus I can not rebuild Discourse when using your plugin. I get this error:

> NoMethodError: undefined method `attributes' for PostSerializer:Class /var/www/discourse/plugins/discourse-qa/plugin.rb:33:in `class:PostSerializer’

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [August 9, 2017, 4:50am UTC](https://meta.discourse.org/t/question-answer-plugin/56032/42 "2017-08-09T04:50:10Z")

</div>

Thanks for the bug report. Fixed.

[https://github.com/angusmcleod/discourse-qa/commit/3410a6fd784f0163dd0466730d0e90185ad73bdd](https://github.com/angusmcleod/discourse-qa/commit/3410a6fd784f0163dd0466730d0e90185ad73bdd)

---

<div class="post-metadata">

### Author: ![jwermers](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@jwermers](https://meta.discourse.org/u/jwermers)
#### Post date: [August 9, 2017, 4:13pm UTC](https://meta.discourse.org/t/question-answer-plugin/56032/43 "2017-08-09T16:13:11Z")

</div>

Works great! Thanks so much.

---

<div class="post-metadata">

### Author: ![Brock\_Busby](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/brock_busby/32/118746_2.png) [@Brock\_Busby](https://meta.discourse.org/u/Brock_Busby)
#### Post date: [August 24, 2017, 5:23pm UTC](https://meta.discourse.org/t/question-answer-plugin/56032/44 "2017-08-24T17:23:57Z")

</div>

> [@angus](#):
>
> You can see it in action here

Trying to view your Q&A plugin in action but getting a “This site can’t be reached” message

> **[Screenshot](https://prnt.sc/gcl2gu)**
>
> Captured with Lightshot

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [August 25, 2017, 12:55am UTC](https://meta.discourse.org/t/question-answer-plugin/56032/45 "2017-08-25T00:55:21Z")

</div>

Yeah, I just took that sandbox down. I’m making a new one.

[Previous page](https://meta.discourse.org/t/question-answer-plugin/56032.md?page=1)

[Next page](https://meta.discourse.org/t/question-answer-plugin/56032.md?page=3)
