# Topic Ratings Plugin

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

<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: [December 6, 2017, 8:52am UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/124 "2017-12-06T08:52:48Z")

</div>

Hey, Santa Angus! Got some room in your busy schedule? 🙂

[[feature request] Show the count of reviews along with the avg score · Issue #11 · paviliondev/discourse-ratings · GitHub](https://github.com/angusmcleod/discourse-ratings/issues/11)

---

<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: [December 7, 2017, 9:23am UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/125 "2017-12-07T09:23:47Z")

</div>

Added 🎅 Setting is `rating_show_count`; default is false.

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

See further: [https://discourse.angusmcleod.com.au/t/the-400-blows-truffaut/151](https://discourse.angusmcleod.com.au/t/the-400-blows-truffaut/151)

---

<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: [December 7, 2017, 12:12pm UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/126 "2017-12-07T12:12:57Z")

</div>

Dear Santa, thank you very much! I always believed you were real 😊

---

<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: [December 16, 2017, 10:05pm UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/127 "2017-12-16T22:05:36Z")

</div>

Thanks for Your time. Ok i will learn how to do it all becouse im not a programmer.. Need some time. Pls tell me - should i learn a ruby laungage or not really ? Should i know somethink more ? How to learn it as fast as it possible (not for be a pro - just for myself needs)

---

<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: [January 2, 2018, 11:20am UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/128 "2018-01-02T11:20:25Z")

</div>

@dalerka @hnaseri As discussed, I’ve updated the average / count style. It now looks like this:

![54 PM](https://global.discourse-cdn.com/meta/original/3X/b/d/bdc552b3b803a32ba9c95fa130c0c6d146c1b632.png)

Both the Amazon style and the use of an emoji has issues. I think it’s best we keep it simple.

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

Thanks for your suggestions 👍

---

<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: [January 2, 2018, 12:18pm UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/129 "2018-01-02T12:18:21Z")

</div>

Thanks, Angus! I totally agree with you on KISS, but genuinely curious if you could expand on issues with Amazon’s approach. Is it about UX or Discourse-related?

---

<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: [January 2, 2018, 1:52pm UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/130 "2018-01-02T13:52:05Z")

</div>

There aren’t any inherent flaws with Amazon’s rating UI/UX or any inherent limitations in Discourse, it would just take considerably more work to achieve the same result in this plugin and there would be various UX tweaks to their approach and decisions that you’d need to make.

Effectively it would be a new feature-set rather than a UI tweak, which is all that is required for now.

Off the top of my head, some things you’d need to do would be:

1. Fractional stars, which would entail a refactor of the CSS. Albeit, this has the minor caveat that the fractional star in Amazon typically does not represent the actual average. See the screenshot below for an example (4.5 according to the stars, 4.7 according to the text)

2. Provide the rating breakdown from the server and set up the UI so that it’s consistent with the Discourse UI, e.g. the bar chart would be a new UI element you’d need to build specifically for this.

3. Interactivity of the rating breakdown, i.e. in Amazon if you click on one of the ratings you see just those ratings. Once a rating breakdown is provided, the ability to filter the rating posts by rating is the natural next step.

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

Not to say that I wouldn’t want to do each of all of these things at some point, just not right now, particularly as these kind of features get more relevant when you’re dealing with consistently large volume of ratings, which (as far as I’m aware) we’re yet to see with this plugin.

---

<div class="post-metadata">

### Author: ![Boogs](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/boogs/32/140183_2.png) [@Boogs](https://meta.discourse.org/u/Boogs)
#### Post date: [January 9, 2018, 1:32am UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/131 "2018-01-09T01:32:15Z")

</div>

This is awesome!

I’ve been thinking how awesome a Discourse / ecommerce integration would be. There are heaps of third-party reviews systems, but they all to some extent take the SEO and community engagement away from your site.

IMO, this plugin + your Q&A plugin would work very nicely! Basically you could relate the post to a particular product (from say a CSV or XML product feed or ecommerce CMS’s API). I guess the ratings threads would need a way to restrict topic creation so that there is only one thread per product.

On the ecommerce CMS side you’d have some kind of widget that shows a snippet of the ratings and Q&A’s for that product, similar to the WP / Discourse integration.

Thoughts?

---

<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: [January 9, 2018, 3:29am UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/132 "2018-01-09T03:29:30Z")

</div>

Yes that’s all doable. I haven’t been doing a lot of work on the QnA plugin, so if you want to use that in a serious way you’ll need to take a close look at it and test its functionality thoroughly.

> [@Boogs](#):
>
> I guess the ratings threads would need a way to restrict topic creation so that there is only one thread per product.

Not entirely sure what you mean here, but this would seem to be something your moderators would handle, at least initially.

> [@Boogs](#):
>
> On the ecommerce CMS side you’d have some kind of widget that shows a snippet of the ratings and Q&A’s for that product, similar to the WP / Discourse integration.

Sounds a bit like you may want to also use [Topic List Previews](https://meta.discourse.org/t/topic-list-previews/41630).

---

<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: [January 18, 2018, 12:29pm UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/133 "2018-01-18T12:29:36Z")

</div>

🤪 Today I updated the plugin to `(fd25572)` and the _Rating-stars_ disappeared from items of _topics list_ view and on _suggested topics_ list (i.e. I can still see the stars on a topic page).

I cannot find any elements with `.topic-rating` class in the source code of the _topic list_ view. Is it a bug or is there a new setting I should enable?

---

<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: [January 19, 2018, 12:42am UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/134 "2018-01-19T00:42:42Z")

</div>

Yup, minor bug. It will work as normal now. Thanks for reporting.

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

---

<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: [January 19, 2018, 6:26am UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/135 "2018-01-19T06:26:33Z")

</div>

Thanks! So, (just for the record) previously the plugin rendered the `.topic-rating` nested under `.social-footer` and now it renders nested under `.topic-title` (in a _topic-list_ view).

Now, I also see that in the _suggested topics_ list sometimes (randomly) the `.topic-rating` and `.topic-excerpt` elements don’t get rendered at all. Any ideas why?

 ![image](https://global.discourse-cdn.com/meta/original/3X/9/0/90e0b8893e5b1f0fc5947f827369ca5957e2bc4d.png)

UPDATE: Don’t know why, but the later issue with excerpt and rating not rendering randomly has suddenly disappeared. Magic 😄

---

<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: [January 19, 2018, 7:48am UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/136 "2018-01-19T07:48:04Z")

</div>

Hm yeah. This is all about plugin outlet placement in the topic list item template(s). The Ratings plugin is now using the `topic-list-after-title` outlet.

I’ve handled the case you’re referring to. For social style, the plugin outlet will render content in the gutter now.

[https://github.com/angusmcleod/discourse-topic-previews/commit/2f3d069d93e988f784bcacd64aac8c77a4fc23ad](https://github.com/angusmcleod/discourse-topic-previews/commit/2f3d069d93e988f784bcacd64aac8c77a4fc23ad)

---

<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: [January 19, 2018, 10:29am UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/137 "2018-01-19T10:29:18Z")

</div>

Haha, I’m sorry, didn’t mean to distract you.  
The `after-title` position was actually preferable for me (even with Social style). My point was to help other people fix styling (target the right element). I made few CSS changes and removed hiding an extra `middot`.

So, if possible can you keep it _the new way_ (i.e. rendering at _after-title_)?

UPDATE: Also with the recent update the `.topic-ratings` element doesn’t render on mobile (with _social style_ topic list enabled). So, to keep it simple, maybe just render after title?

---

<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: [January 20, 2018, 4:04am UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/138 "2018-01-20T04:04:05Z")

</div>

I’ve [fixed the mobile outlet](https://github.com/angusmcleod/discourse-topic-previews/commit/6ff037ae8a4ab537238570942e8eb02577964525), but I’m sorry, I think it makes more sense for the social style to have the outlet in the footer by default - it’s where all the other topic info is in that style.

If you want to move the element on your instance (i.e. more than just using CSS), you can use jQuery:

```plaintext
Ember.run.scheduleOnce('afterRender', () => {
  const $topicRating = $('.topic-rating');
  const $target = $(target);
  $topicRating.appendTo($target);
});

```

This will make the topic-rating element the first child of whatever container you want to put it in.

---

<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: [January 20, 2018, 5:11am UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/139 "2018-01-20T05:11:22Z")

</div>

No, problem at all! As long as things are kept consistent across updates 🙂  
Thank you for all your hard work!

---

<div class="post-metadata">

### Author: ![Anshul\_TM](https://avatars.discourse-cdn.com/v4/letter/a/8491ac/32.png) [@Anshul\_TM](https://meta.discourse.org/u/Anshul_TM)
#### Post date: [February 1, 2018, 8:13am UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/140 "2018-02-01T08:13:35Z")

</div>

Hey @angus,

I want to extend this to allow for multiple ratings instead of just one.  
e.g. in my case Train reviews can include punctuality, cleanliness, food.

I’ve cloned the repo and exploring the code, a few pointers will be very helpful.

---

<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: [February 2, 2018, 2:21am UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/141 "2018-02-02T02:21:22Z")

</div>

Do you mean multiple ratings on one topic? Yes that could be done I suppose. Basically, you’ll need to add in additional custom fields, wherever the current rating custom fields are. And some conditional logic to handle the calculation of the average separately for each type.

For example, you may end up with something like this for saving the rating when a post is created:

```plaintext
  DiscourseEvent.on(:post_created) do |post, opts, user|
    if opts[:rating] || opts[:rating_type2]
      post.custom_fields['rating'] = opts[:rating] if opts[:rating]
      post.custom_fields['rating_type2'] = opts[:rating_type2] if opts[:rating_type2]
      post.custom_fields["rating_weight"] = 1
      post.save_custom_fields(true)
      RatingsHelper.handle_rating_update(post, opts)
    end
    ///

```

Then add some conditional logic in `handle_rating_update` to calculate averages and push those averages to the topic, for each type of rating.

---

<div class="post-metadata">

### Author: ![parisa](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@parisa](https://meta.discourse.org/u/parisa)
#### Post date: [February 7, 2018, 5:41pm UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/142 "2018-02-07T17:41:53Z")

</div>

The newest version makes opening the rating topic too slow. for example if other topics would open in two seconds, rating topic opens in 5 seconds.

on the other hand is there an option to remove stars from below topic title and just let them be inside the topic?

---

<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: [February 10, 2018, 1:14pm UTC](https://meta.discourse.org/t/topic-ratings-plugin/39578/143 "2018-02-10T13:14:13Z")

</div>

> [@parisa](#):
>
> The newest version makes opening the rating topic too slow. for example if other topics would open in two seconds, rating topic opens in 5 seconds.

Can you give me an example of this? In my own testing on localhost, and on [https://discourse.angusmcleod.com.au](https://discourse.angusmcleod.com.au), rating topics load at the same speed as any other topic.

> [@parisa](#):
>
> on the other hand is there an option to remove stars from below topic title and just let them be inside the topic?

I’ve added settings for the average ratings in the topic and in the topic list:

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

 ![29%20PM](https://global.discourse-cdn.com/meta/original/3X/1/6/16bcb6c7c95cc0d033fa19efda4baf0a0470cfc1.png)

[Previous page](https://meta.discourse.org/t/topic-ratings-plugin/39578.md?page=6)

[Next page](https://meta.discourse.org/t/topic-ratings-plugin/39578.md?page=8)
