How can I develop a voting system where users can vote other users (i.e a reputation-like system)?

How can I develop a voting system where users can vote other users (i.e a reputation-like system)?

<strong>Question: How can I use the acts_as_votable gem to get a "user reputation" system working for my user model? I'm unsure of the best approach given the code below.</strong>

Question: How can I use the acts_as_votable gem to get a "user reputation" system working for my user model? I'm unsure of the best approach given the code below.

Essentially, I have a user model. What I want to do is, for certain users (namely admin accounts), they can access a page where all users are viewable and "vote" for the user in terms of their reputation.

My issue is that, from my understanding, the gem requires both a acts_as_votable, and a acts_as_voter within the model.

However, since the voter is the user, and the votable is the user, too, I'm unsure how to proceed with this.

What I've done so far is:

Gem file:

gem 'acts_as_votable'

Console rails generate acts_as_votable:migration rake db:migrate

The model I have is:

class User < ActiveRecord::Base
end

Based on this, what would be the recommended solution?

I've tried creating another model, called "UserReputation", and generated relevant controllers and views.

My issue with this approach is that when I'm in the index page, for user reputations, it does not show all the users against a like and dislike button.

I understand why this is the case, as UserReputation is created by a user, and then users would vote for a UserReputation (Analogous to a forum post). This isn't what I want to do, but I was following a tutorial for this.

Essentially, if this is the only way to go, is it possible to put a "link" between User and UserReputation, so they are tied together?

This is my attempted code:

class User < ActiveRecord::Base
  acts_as_voter
  has_many :user_reputations
end

class UserReputation < ActiveRecord::Base acts_as_votable belongs_to :user end

class UserReputationsController < ApplicationController def index @user_reputations = UserReputation.all @users = User.all end end

Index for User Reputations:

<table class="table" style="font-size: 18px;">
    <thead>
        <tr>
            <th> Username </th>
            <th> Reputation </th>
            <th> Upvote </th>
            <th> Downvote </th>
        </tr>
    </thead>
    <tbody>
        <% @user_reputations.each do |user_reputation| %>
            <tr>
                <td> <%= user.email %> </td>
                <th> <%= "Reputation" %> </th>
                <td> <%= link_to like_user_reputation_path(user), method: :put do %>
like
<%= user_reputation.get_upvotes.size %>
<% end %> </td>
<td> <%= link_to dislike_user_reputation_path(user), method: :put do %>
dislike
    <%= user_reputation.get_downvotes.size %>
    <% end %> </td>
            </tr>
        <% end %>
    </tbody>
</table>
<br>


ruby-on-rails ruby

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Explain Ruby on rails MVC

Our Ruby on Rails Training will provide you to learn about Rails and web applications development with realty. Our Ruby on Rails Course also includes live sessions.

Pros & Cons you must know before using Ruby on Rails for your startup

Click here, free ruby on rails course videos for you. It shows you best way to complete Ruby certification. OnlineITGuru guides you towards easy Web script

Ruby on Rails Performance Tuning

Synchronises Assets between Rails and S3. Contribute to AssetSync/asset_sync development by creating an account on GitHub.

DoubleRenderError in Ruby on Rails

How do I solve the DoubleRenderError by using before_action.To practice my rails skills, I decided to make a website about events. It is a website mainly between organizations, who hold an event and volunteers, who join the event. Among all the problems I encountered, I want to share the DoubleRenderError because it bothered me for a long time and how I solve the problem.

Live Updates in Ruby on Rails with ActionCable Feature

There are times when one as a Ruby on Rails developer wants to implement a real-time feature, like a chat application, and after digging a bit you find a framework's feature named ActionCable, sounds new and scary, right? Fear not, I'll try to explain it as simple as possible so that at the end of this article you'll feel comfortable with the subject.