# Topic Ratings Plugin

**URL:** https://meta.discourse.org/t/topic-ratings-plugin/39578
**Category:** Plugin
**Tags:** pavilion
**Created:** [2월 14, 2016, 9:06오후 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578 "2016-02-14T21:06:53Z")
**Posts on this page:** 20
**Page:** 6

<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: [6월 28, 2017, 11:47오후 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/103 "2017-06-28T23:47:15Z")

</div>

If you’re talking about this plugin and not polls:

- A user can only submit one rating per topic. Once you’ve submitted your rating, you can still post in the topic, but the rating controls will not appear in the composer again.
- Rating controls will appear in:
  1. Topics in a category with ratings enabled
  2. Topics with a ratings tag

As @cpradio said, this plugin uses both `TopicCustomFields` and `PostCustomFields`, however I can’t see any reason why moving a topic from one category to another would affect the ratings control visibility logic. The logic for deciding whether to show the ratings controls in the composer is dependent on `CategoryCustomFields` which are not being migrated in this case.

Topic and post custom fields are used to store ratings and average ratings, not to decide whether to show rating controls.

---

<div class="post-metadata">

### Author: ![tophee](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tophee/32/73406_2.png) [@tophee](https://meta.discourse.org/u/tophee)
#### Post date: [6월 29, 2017, 5:36오전 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/104 "2017-06-29T05:36:25Z")

</div>

> [@angus](#):
>
> If you’re talking about this plugin and not polls:

Yes, it’s ratings, not polls.

> [@angus](#):
>
> The logic for deciding whether to show the ratings controls in the composer is dependent on CategoryCustomFields which are not being migrated in this case.

So are you saying this is the reason why I’m not seeing the ratings controls? No, I think you’re saying that the `CustomCategoryFields` are not being moved because I moved the post _into_ rather than out of a rating category.

---

<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: [6월 30, 2017, 5:49오전 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/105 "2017-06-30T05:49:03Z")

</div>

> [@tophee](#):
>
> CustomCategoryFields are not being moved because I moved the post into rather than out of a rating category.

Correct. CategoryCustomFields are not affected by topics being moved.

tbh, I haven’t tested the ratings client logic in the scenario you’re dealing with: moving an existing topic into a ratings category. I’ll take a look at that scenario this weekend. Thanks.

---

<div class="post-metadata">

### Author: ![hnaseri](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hnaseri/32/120660_2.png) [@hnaseri](https://meta.discourse.org/u/hnaseri)
#### Post date: [10월 2, 2017, 8:35오전 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/107 "2017-10-02T08:35:18Z")

</div>

Can you add [aggregated rating](http://schema.org/AggregateRating) schema support to 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: [10월 3, 2017, 12:29오전 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/108 "2017-10-03T00:29:18Z")

</div>

If I understand correctly how [schema.org](http://schema.org) works (which I’m still not sure I do, even after a using it a few times), the schema for AggregateRating will only work if it is within the scope of a ‘type’. It seems these scope types support AggregateRating:

 ![02 AM](https://global.discourse-cdn.com/meta/original/3X/f/9/f9ae4b9795210b5880c78eea3aed293cc76342fc.png)

As it (seems) to be type dependent, I’m not sure it makes sense to support it directly in this plugin as that would involve choosing a particular type, e.g. Product or Service. Not all users of this plugin will be using it for one particular type.

If someone else knows more about schemas and can confirm or deny this, that would help (@vinothkannans?)

You could still add schema support for AggregateRating within the scope of a particular type, by forking this plugin and adding a new file:

`app/views/connectors/topic_header/aggregate_rating.html.erb`

the contents of which would look something like one of the existing [schema.org](http://schema.org) markup blocks in the `topics/show.html.erb` view e.g. the [tags markup](https://github.com/discourse/discourse/blob/master/app/views/topics/show.html.erb#L21).

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [10월 3, 2017, 6:53오전 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/109 "2017-10-03T06:53:20Z")

</div>

We can add `AggregateRating` by default. In the allowed schema type list it have `CreativeWork`. In Discourse we are using [`DiscussionForumPosting`](http://schema.org/DiscussionForumPosting) as default schema type. It is a part of `CreativeWork` (CreativeWork \> Article \> SocialMediaPosting \> DiscussionForumPosting). So it is 100% appropriate to use `AggregateRating` in topic ratings 👍.

I manually tested this functionality in [Google’s testing tool](https://search.google.com/structured-data/testing-tool).

---

<div class="post-metadata">

### Author: ![hnaseri](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hnaseri/32/120660_2.png) [@hnaseri](https://meta.discourse.org/u/hnaseri)
#### Post date: [10월 4, 2017, 4:37오전 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/110 "2017-10-04T04:37:19Z")

</div>

I cant edit post below a rating topic anymore.

---

<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: [10월 5, 2017, 12:28오전 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/111 "2017-10-05T00:28:05Z")

</div>

> [@hnaseri](#):
>
> I cant edit post below a rating topic anymore.

Thanks for the report. Bug fixed.

[https://github.com/angusmcleod/discourse-ratings/commit/b0b644ea85bcb43b8caf31603a23b1a865cfb742](https://github.com/angusmcleod/discourse-ratings/commit/b0b644ea85bcb43b8caf31603a23b1a865cfb742)

> [@hnaseri](#):
>
> Can you add aggregated rating schema support to this plugin?

As per @vinothkannans’s advice, I’ve added `aggregateRating` as part of `CreativeWork`.

 ![Screenshot at Oct 05 08-26-45](https://global.discourse-cdn.com/meta/original/3X/1/c/1c47911d43f1145f0cb1f059c77c111ca060591f.png)

[https://github.com/angusmcleod/discourse-ratings/commit/85f82fc2e8843fc8a95847bc82be34eec2b38fc5](https://github.com/angusmcleod/discourse-ratings/commit/85f82fc2e8843fc8a95847bc82be34eec2b38fc5)

@vinothkannans You probably are already aware that Google’s structured data testing tool is complaining about the DiscussionForumPosting microdata for core Discourse topic views not having images. I’m not sure if that omission means the DiscussionForumPosting microdata blocks will be ignored?

 ![Screenshot at Oct 05 08-25-58](https://global.discourse-cdn.com/meta/original/3X/c/4/c41b62becf45d39df82ab01044bc940ff6afd748.png)

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [10월 5, 2017, 2:23오후 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/112 "2017-10-05T14:23:41Z")

</div>

I think it needs some changes in both on your code and Discourse core. I will create a PR once it changed in core. For now okay 👍

---

<div class="post-metadata">

### Author: ![dalerka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dalerka/32/120265_2.png) [@dalerka](https://meta.discourse.org/u/dalerka)
#### Post date: [11월 25, 2017, 7:02오전 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/113 "2017-11-25T07:02:55Z")

</div>

Today I enabled this plugin for the first time on a pretty fresh discourse install and I don’t see the _star-rating_ buttons in a reply box (composer) and I get the following error:  
[https://github.com/angusmcleod/discourse-ratings/issues/10](https://github.com/angusmcleod/discourse-ratings/issues/10)

Update: after rebuilding the discourse app, I can no longer reproduce the `TypeError...` but I still don’t see the _star-ratings_ buttons.

---

<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: [11월 26, 2017, 12:45오후 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/114 "2017-11-26T12:45:29Z")

</div>

Hey :). The `addObject` exception is actually unrelated to this plugin. It’s a Discourse exception. I’ve been meaning to report it.

> [@Composer Messages Exception](https://meta.discourse.org/t/composer-messages-exception/74829):
>
> Steps to repro: On a vanilla instance with a new user, start to compose your first message. The education.new\_topic composer message will appear. Dismiss it. Write until the draft process is triggered and the draft saves. Refresh the page. The composer will re-open with your draft. An exception will be thrown. [\_findMessages](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/components/composer-messages.js.es6#L157) attempts to add the welcome message to queuedForTyping, which is null at the time it is assigned. The issue is with the sequence of reseting queuedForTyping …

As to the ratings buttons not appearing, I can’t repro it unfortunately. Can you send me some screenshots with the console open?

I tested it locally and on my sandbox here: [https://discourse.angusmcleod.com.au/c/ratings](https://discourse.angusmcleod.com.au/c/ratings)

Composer:

 ![51 PM](https://global.discourse-cdn.com/meta/original/3X/b/5/b5d7f5fa35db5f205470c04a31881d88ab00f15c.png)

Topic:

 ![06 PM](https://global.discourse-cdn.com/meta/original/3X/e/2/e26eabdeb9971f436a11433a66bd456600bee4e9.png)

Topic List:  
 ![39 PM](https://global.discourse-cdn.com/meta/optimized/3X/f/9/f9be74fe67ae462aa267fcd34e490d8b90f5960b_2_690x45.png)

---

<div class="post-metadata">

### Author: ![dalerka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dalerka/32/120265_2.png) [@dalerka](https://meta.discourse.org/u/dalerka)
#### Post date: [11월 27, 2017, 5:51오전 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/115 "2017-11-27T05:51:54Z")

</div>

Thanks! and sorry for undeserved attribution of a bug. 🙂  
On screenshots you can see no errors in the Console and no stars-buttons in the Composer or the `average-rating` div.

 ![Rating_plugin_bug](https://global.discourse-cdn.com/meta/original/3X/0/3/03c33a53808649aa342dbf60df6212e7cd016adc.png)

 ![Rating_plugin_Div](https://global.discourse-cdn.com/meta/original/3X/9/4/9495c00eb6b339c4b9fadd90f17c0db99ae3db57.png)

**Update:**

1. The plugin works well if the post is created in the _rating-enabled_ category initially. However it doesn’t work for the posts in such directory which have been created/edited before _error-less_ installation of this plugin (i.e. I had some Discourse-related error on the server when initially installed this plugin, but after _rebuild_ there was no error).

2. Unfortunately the plugin doesn’t appear to be working for the posts initially created in a _non-rating_ category, when those posts have been moved to a _rating-enabled_ category, which is sad 😢

 ![Rating_plugin_Reply_no_stars](https://global.discourse-cdn.com/meta/original/3X/8/e/8e2336b3ba7d63bbdc10618d4267fbd03cc54564.png)

 ![Rating_plugin_change_category](https://global.discourse-cdn.com/meta/original/3X/2/3/23232212586ede28b56207f5b907a205ac02c008.png)

---

<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: [11월 27, 2017, 10:56오전 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/116 "2017-11-27T10:56:46Z")

</div>

Thanks for figuring that out. It should work for such ‘pre-existing’ topics now.

[https://github.com/angusmcleod/discourse-ratings/commit/2dd9fb80284e9b339f240008a6e8526dd3cb6aac](https://github.com/angusmcleod/discourse-ratings/commit/2dd9fb80284e9b339f240008a6e8526dd3cb6aac)

---

<div class="post-metadata">

### Author: ![dalerka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dalerka/32/120265_2.png) [@dalerka](https://meta.discourse.org/u/dalerka)
#### Post date: [11월 27, 2017, 12:46오후 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/117 "2017-11-27T12:46:40Z")

</div>

Thank you that was fast! Indeed, now I can rate the pre-existing topics. However I can also place multiple ratings with the same user, which kind of allows for rating-abuse:

 ![Rating_plugin_Reply_again](https://global.discourse-cdn.com/meta/original/3X/6/6/667a3047a0e9916756c6332477bb0c5b7a7c97c8.png)

---

<div class="post-metadata">

### Author: ![Tumi](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@Tumi](https://meta.discourse.org/u/Tumi)
#### Post date: [11월 28, 2017, 12:14오전 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/118 "2017-11-28T00:14:12Z")

</div>

Hi , nice plugin

It is possible to create a ranking of this ratings ?

For example i wanna to show the most importand topic from all category or selected in admin menu  
For example i want to show on the sidebar Top 10 best rating topic from category X and category Y  
It is possiible ?  
It would be perfect if the top post will depend on Number of stars + number of votes (quality ratio)

---

<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: [11월 28, 2017, 12:55오전 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/119 "2017-11-28T00:55:04Z")

</div>

Given enough time, everything breaks, aka entropy … fixed as well 🙂

[https://github.com/angusmcleod/discourse-ratings/commit/5d08b456a97e884fc41028323a98007fc0b07a7c](https://github.com/angusmcleod/discourse-ratings/commit/5d08b456a97e884fc41028323a98007fc0b07a7c)

---

<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: [11월 28, 2017, 1:07오전 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/120 "2017-11-28T01:07:43Z")

</div>

Hey

> [@Tumi](#):
>
> It is possible to create a ranking of this ratings ?

Yes, it’s possible. In a separate plugin you could add a new topic list that sorts topics based on the `average_rating` topic custom field.

Here’s an example of how to create a new topic list that is sorted by a custom field:

- [discourse-events/plugin.rb at main · angusmcleod/discourse-events · GitHub](https://github.com/angusmcleod/discourse-events/blob/master/plugin.rb#L136)

> [@Tumi](#):
>
> i want to show on the sidebar Top 10 best rating topic from category X and category Y

Well, you’ll need a sidebar first. Then a widget that has a topic list in it. Here’s some I prepared earlier:

[https://github.com/angusmcleod/discourse-layouts](https://github.com/angusmcleod/discourse-layouts)  
[https://github.com/angusmcleod/layouts-topic-list](https://github.com/angusmcleod/layouts-topic-list)

So all you need to do is change the topic list in the layouts-topic-list widget to the topic list you created in your new plugin.

1. Follow the [beginners guide to creating a plugin](https://meta.discourse.org/t/beginners-guide-to-creating-discourse-plugins-part-1/30515)

2. Add the layouts plugin with the topic list widget

3. Copy / paste the new topic list code I’ve linked above

4. Change a few variable names and urls in the topic list widget and the topic list code.

---

<div class="post-metadata">

### Author: ![meglio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meglio/32/71444_2.png) [@meglio](https://meta.discourse.org/u/meglio)
#### Post date: [11월 29, 2017, 2:57오후 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/121 "2017-11-29T14:57:15Z")

</div>

For some reason, ratings checkbox is now shown in some composers, and users don’t understand why?

I never configured it or turned on anything like that.

---

<div class="post-metadata">

### Author: ![meglio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meglio/32/71444_2.png) [@meglio](https://meta.discourse.org/u/meglio)
#### Post date: [11월 29, 2017, 10:30오후 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/122 "2017-11-29T22:30:04Z")

</div>

I think I caught it: it is shown when EDITING messages. Even if it’s turned off.

---

<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: [11월 30, 2017, 1:03오전 UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/123 "2017-11-30T01:03:28Z")

</div>

Thanks for the report 👍 Fixed.

[https://github.com/angusmcleod/discourse-ratings/commit/a5dbae0f9e8dfb633f0eb787502aab491e50c1ca](https://github.com/angusmcleod/discourse-ratings/commit/a5dbae0f9e8dfb633f0eb787502aab491e50c1ca)

[이전 페이지](https://meta.discourse.org/t/topic-ratings-plugin/39578.md?page=5)

[다음 페이지](https://meta.discourse.org/t/topic-ratings-plugin/39578.md?page=7)
