# Discourse Gamification - Getting 404 / MissingAttributeError on /leaderboard route

**URL:** https://meta.discourse.org/t/discourse-gamification-getting-404-missingattributeerror-on-leaderboard-route/404855
**Category:** Bug
**Tags:** gamification
**Created:** [9 ביוני,‏ 2026,‏ 3:51pm UTC](https://meta.discourse.org/t/discourse-gamification-getting-404-missingattributeerror-on-leaderboard-route/404855 "2026-06-09T15:51:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![glob-canard.4x](https://avatars.discourse-cdn.com/v4/letter/g/e8c25b/32.png) [@glob-canard.4x](https://meta.discourse.org/u/glob-canard.4x)
#### Post date: [9 ביוני,‏ 2026,‏ 3:51pm UTC](https://meta.discourse.org/t/discourse-gamification-getting-404-missingattributeerror-on-leaderboard-route/404855/1 "2026-06-09T15:51:00Z")

</div>

So, I recently decided to enable gamification and immediately ran into an issue where the `/leaderboard` route was returning a 404 error. The backend had over 800k score records calculated and the permissions checked out, but the page itself wouldn’t load.

Checking the server logs showed:  
`ActiveModel::MissingAttributeError (missing attribute 'admin' for User)`

While digging through the plugin code, I noticed in `lib/discourse_gamification/leaderboard_cached_view.rb` that the user query uses a specific .select string to pull columns for the leaderboard:

```ruby
.select(
"users.id, users.name, users.username, users.uploaded_avatar_id, p.total_score, p.position",
)

```

Because `users.admin` and `users.moderator` aren’t included in that query, the instantiated user objects don’t have those fields available. It looks like (?) somewhere further down the line during serialization or core layout rendering, a staff check is being triggered on those users, causing Rails to throw the `MissingAttributeError` and fall back to a 404.

I manually edited that file to include `users.admin` and `users.moderator` in the .select block:

```ruby
.select(
  "users.id, users.name, users.username, users.uploaded_avatar_id, users.admin, users.moderator, p.total_score, p.position",
)

```

After restarting the app container, the leaderboard started loading perfectly.

I’m guessing this is a bug (?) or have I completely overthought/overlooked something?

The site is currently on v2026.6.0-latest (47a830330f)

---

<div class="post-metadata">

### Author: ![ted](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ted/32/283882_2.png) [@ted](https://meta.discourse.org/u/ted)
#### Post date: [19 ביוני,‏ 2026,‏ 1:30am UTC](https://meta.discourse.org/t/discourse-gamification-getting-404-missingattributeerror-on-leaderboard-route/404855/2 "2026-06-19T01:30:35Z")

</div>

The error and the explanation you provided match. Unfortunately I was unable to reproduce the issue from `47a830330f` or on `main`. I tried it signed in as an admin and as a regular user, and they both load fine.

As a sanity check I just want to confirm you’re using the version of `gamification` that’s bundled with Discourse core, and doesn’t have the old, stand-alone plugin installed?

Are you able to provide more of the stack trace of where the `MissingAttributeError` is happening?

---

<div class="post-metadata">

### Author: ![glob-canard.4x](https://avatars.discourse-cdn.com/v4/letter/g/e8c25b/32.png) [@glob-canard.4x](https://meta.discourse.org/u/glob-canard.4x)
#### Post date: [19 ביוני,‏ 2026,‏ 8:21pm UTC](https://meta.discourse.org/t/discourse-gamification-getting-404-missingattributeerror-on-leaderboard-route/404855/3 "2026-06-19T20:21:55Z")

</div>

@ted,

Actually, you can feel free to disregard this. I ultimately traced the issue back to a plugin that hooked into the `UserScoreSerializer` that implemented its own narrow `.select()` statement. It wasn’t apparent initially because there was no backtrace provided in `/logs` for the `MissingAttributeError`. Only after digging through and making the call manually through rails to get a full stack trace was I able to pinpoint the errant plugin.

Thanks, and sorry for the false alarm!

---

<div class="post-metadata">

### Author: ![ted](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ted/32/283882_2.png) [@ted](https://meta.discourse.org/u/ted)
#### Post date: [21 ביוני,‏ 2026,‏ 4:33am UTC](https://meta.discourse.org/t/discourse-gamification-getting-404-missingattributeerror-on-leaderboard-route/404855/4 "2026-06-21T04:33:52Z")

</div>

> [@glob-canard.4x](#):
>
> Thanks, and sorry for the false alarm!

No problem! You had an issue and you posted about it. Glad you got it sorted. 🙂

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [22 ביוני,‏ 2026,‏ 9:14am UTC](https://meta.discourse.org/t/discourse-gamification-getting-404-missingattributeerror-on-leaderboard-route/404855/5 "2026-06-22T09:14:17Z")

</div>


