Riley Lambert

Riley Lambert

1548730101

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

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

What is GEEK

Buddha Community

since user_reputation is just one record for each user, my opinion is to set has_one instead of has_many relation between User and UserReputation, here is the setting for model, note: you don’t need to generate migration since user_reputations table already has user_id field

in you model

class User < ActiveRecord::Base
  acts_as_voter
  has_one :user_reputation  # new changes
end

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

in your controller

class UserReputationsController < ApplicationController
  def index
    @users = User.all
    redirect_to user_reputations_path
  end

  def like_user
    @user_reputation = UserReputation.find(params[user_reputation_id])
    @user_reputation.liked_by current_user
    # current_user is available from application controller if you using bcrypt or devise
  end

  def dislike_user
    @user_reputation = UserReputation.find(params[user_reputation_id])
    @user_reputation.downvote_from current_user
  end 
end

in you view

<table class="table" style="font-size: 18px;">
    <thead>
        <tr>
            <th> Username </th>
            <th> Reputation </th>
            <th> Upvote </th>
            <th> Downvote </th>
        </tr>
    </thead>
    <tbody>
        <% @users.each do |user| %>
            <tr>
                <td> <%= user.email %> </td>
                <td> <%= @user.user_reputation.votes_for.size %> </td>
                # here the relation set between user and user_reputation
                # since it set one user only one user_reputation
                # and you can get scope votes_for since it has acts_as_votable
                <td> 
                  <%= link_to "Like", like_user_reputation_path(user_reputation_id: @user.user_reputation.id) %> 
                </td>
                <td> 
                  <%= link_to "dislike", dislike_user_reputation_path(user_reputation_id: @user.user_reputation.id) %> 
                </td>
            </tr>
        <% end %>
    </tbody>
</table>

in your routes file

resources :user_reputations do
  collection { 
    get :like_user   
    put :dislike_user
  }
end

Custom E-Commerce App Development Services Provider Company in USA

Do you want to make a custom E-Commerce mobile app for your business? We at AppClues Infotech is the best E-Commerce mobile app development company in the USA that provides a complete E-Commerce app solution with the current trending technologies & features at an affordable cost.

For more info:
Website: https://www.appcluesinfotech.com/
Email: info@appcluesinfotech.com
Call: +1-978-309-9910

#e-commerce app development #mobile commerce app development #e-ccommerce app development company usa #e-commerce development services usa #custom e-commerce app development #e-commerce app development services

E-Learning App Development: Types, Cost & Features

The growth of the online modes for students has increased since the pandemic. This growth has been possible with the help of E-learning software systems. This software has shown a future with more opportunities, even in this pandemic. This market will grow to a high of 350 billion dollars by 2025. Due to this pandemic, most education organizations have shifted to online modes. So, naturally, this means the need for E-learning software systems will grow. So, do you have a complete idea for your E-learning applications and are planning to develop one for your organization? E-learning product development is not a very difficult process to handle. To make the process easier for you, we have added the types of e-learning apps, its features, benefits, development cost and much more in this blog. To read more click on the link.

#e-learning web portals #e-learning development companies #development of software for e-learning #e-learning web portalsmobile applications for e-learning #e-learning product development #app development

How to build an learning app like BYJU's| Cost to build app like BYJU's?

Due to schools & Colleges being closed due to Covid-19 Pandemic, the need for e-learning platforms like Byju’s has seen a rapid rise among school students. The rise is so fast that in just 3 months from the beginning of lockdowns its user base increased by twice.

Want to help school students learn with creative methods from an e-learning app?
WebClues Infotech is there for you to bring your vision to reality with its highly skilled e-learning App Development team. With past experience in developing different types of e-learning solutions like AshAce Papers, EduPlay Cloud, Squared, and many more, WebClues Infotech is fully equipped to develop an e-learning app development solution based on your need

Want more information on Byju’s like e-learning app Development?

Visit our detailed guide at https://www.webcluesinfotech.com/how-to-create-an-elearning-app-like-byjus/

#how to build an learning app like byju's? #how to develop a learning app like byju's features & cost #how to create an app like byju's #how much does it cost to develop an app like byjus #e-learning app development solution #e-learning apps development

Fredy  Larson

Fredy Larson

1595059664

How long does it take to develop/build an app?

With more of us using smartphones, the popularity of mobile applications has exploded. In the digital era, the number of people looking for products and services online is growing rapidly. Smartphone owners look for mobile applications that give them quick access to companies’ products and services. As a result, mobile apps provide customers with a lot of benefits in just one device.

Likewise, companies use mobile apps to increase customer loyalty and improve their services. Mobile Developers are in high demand as companies use apps not only to create brand awareness but also to gather information. For that reason, mobile apps are used as tools to collect valuable data from customers to help companies improve their offer.

There are many types of mobile applications, each with its own advantages. For example, native apps perform better, while web apps don’t need to be customized for the platform or operating system (OS). Likewise, hybrid apps provide users with comfortable user experience. However, you may be wondering how long it takes to develop an app.

To give you an idea of how long the app development process takes, here’s a short guide.

App Idea & Research

app-idea-research

_Average time spent: two to five weeks _

This is the initial stage and a crucial step in setting the project in the right direction. In this stage, you brainstorm ideas and select the best one. Apart from that, you’ll need to do some research to see if your idea is viable. Remember that coming up with an idea is easy; the hard part is to make it a reality.

All your ideas may seem viable, but you still have to run some tests to keep it as real as possible. For that reason, when Web Developers are building a web app, they analyze the available ideas to see which one is the best match for the targeted audience.

Targeting the right audience is crucial when you are developing an app. It saves time when shaping the app in the right direction as you have a clear set of objectives. Likewise, analyzing how the app affects the market is essential. During the research process, App Developers must gather information about potential competitors and threats. This helps the app owners develop strategies to tackle difficulties that come up after the launch.

The research process can take several weeks, but it determines how successful your app can be. For that reason, you must take your time to know all the weaknesses and strengths of the competitors, possible app strategies, and targeted audience.

The outcomes of this stage are app prototypes and the minimum feasible product.

#android app #frontend #ios app #minimum viable product (mvp) #mobile app development #web development #android app development #app development #app development for ios and android #app development process #ios and android app development #ios app development #stages in app development

Digital Wallet App Development | Mobile Payment App Development | e-Wallet App Development

Are you looking for the most trusted and custom mobile wallet development company in USA? We at AppClues Infotech offering reliable & productive mobile wallet app development services with advanced technologies and functionalities. Hire dedicated mobile wallet designer & developers from us at the best price for your business requirements.

Our Mobile Wallet App Development Services
• Custom Mobile Wallet App Solution
• Cryptocurrency Wallet App Development
• Digital Wallet App Development
• Mobile Payment App Development
• Mobile Wallet UI/UX Designing

For more info:
Website: https://www.appcluesinfotech.com/
Email: info@appcluesinfotech.com
Call: +1-978-309-9910

#digital wallet app development #mobile payment app development #e-wallet app development #digital e-wallet app development company #digital wallet app development services #ewallet app development