<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:
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
class UserReputationsController < ApplicationController
@user_reputations = UserReputation.all
@users = User.all
Index for User Reputations:
<table class="table" style="font-size: 18px;">
<th> Username </th>
<th> Reputation </th>
<th> Upvote </th>
<th> Downvote </th>
<% @user_reputations.each do |user_reputation| %>
<td> <%= user.email %> </td>
<th> <%= "Reputation" %> </th>
<td> <%= link_to like_user_reputation_path(user), method: :put do %>
<%= user_reputation.get_upvotes.size %>
<% end %> </td>
<td> <%= link_to dislike_user_reputation_path(user), method: :put do %>
<%= user_reputation.get_downvotes.size %>
<% end %> </td>
<% end %>
Rails is a development tool which gives web developers a framework, providing structure for all the code they write. The Rails framework helps developers to build websites and applications. Ruby is a programming language stronger than Perl and more object-oriented than Python. It is being developed with increasing productivity.
Understanding the pros and cons of Ruby on Rails versus PHP is important when deciding how to create your business-critical applications.
Originally published at https://www.engineyard.com
There’s more than one way to build a web application. No matter what type of application you are trying to create, your programmers have their preferred approach and their preferred code languages to accomplish the task. In the world of web applications, most program developers have to decide between Ruby on Rails versus PHP.
Ruby on Rails consists of Ruby, which is a scripting language, and Rails, which is a web development framework; PHP is a server-side scripting language. Both programming languages have been around since the mid-1990s, but PHP rules the web, while Ruby on Rails is more popular for business web applications. Understanding the pros and cons of Ruby on Rails versus PHP is important when deciding how to create your business-critical applications.Ruby on Rails Versus PHP at First Glance
Both Ruby on Rails and PHP are open source, so there are no licensing fees. However, because PHP is used to run most of today’s web systems, there are more PHP programmers than Ruby developers, which means there is a larger pool of PHP experts and a larger open source library to draw from.
Part of the reason PHP is more popular with web developers is because it is easier to learn. PHP is also an object-oriented programming language, which makes it easier to be more creative and tackle tougher software challenges.
Once web developers master PHP, many of them choose to add Ruby on Rails to their expertise because of the advantages and power that Ruby on Rails offers for business application development. Ruby and Rails were created together to deliver web solutions, and the primary difference between PHP and Ruby on Rails is that Rails requires you to understand the full stack, including the web server, application server, and database engine.
Since both Ruby and PHP are open source, the support of the programming communities is an important differentiator. PHP has more deployments so it has a larger developer community, but the Ruby on Rails community is very skilled and enthusiastic and they want to share, so there is a growing library of ready-to-use Ruby gems.Differences in Deployment
When it comes to deployment, PHP is very easy to implement. You simply transfer files to the web server via FTP and that’s it. With PHP, you don’t need to worry about the web stack. Most hosting services use a combination of open source for the stack, including Linux, Apache, MySQL, and PHP (LAMP), so once the files are loaded, they just run. That’s the advantage of server-side software.
Ruby on Rails is more complex to deploy because you have to know the full stack. That means knowing the details of the web server (e.g., Apache or NginX), as well as the database. You have to go through more steps, such as precompiling assets to make sure all the right files are there. This is the price of being able to design and deploy more complex applications.
Where Ruby on Rails really shines is in the software development process itself. Since Ruby is an object-intensive language, everything is an object, including classes and modules, with Rails providing an integrated test framework. PHP is not always object-oriented, so coding can be laborious and time-consuming. Applications can be built and tested in Ruby on Rails much faster than in PHP, so even if there is some debugging involved, Ruby on Rails dramatically reduces the time to deployment.
As noted above, PHP applications are relatively simple to deploy since there is no stack to worry about, and they are relatively inexpensive to host. Hosting Ruby on Rails applications is another story. Not all hosting providers will support Ruby on Rails, and those that do usually add additional a la carte fees because Ruby applications require more services.The Business Case for Ruby on Rails versus PHP
While it’s clear that Ruby is a more difficult programming language to master, in many ways, it is a more robust language that is better suited for creating business applications. PHP was created specifically for the web, but Ruby on Rails offers much more.
For one thing, Ruby on Rails applications tend to be cleaner and more compact. Because PHP is so simple, it lends itself to sloppy coding that can be impossible to maintain. Ruby has the advantage of being more elegant and concise, and the documentation for Ruby applications tends to be generated with the code so anyone can make revisions or upgrades.
Most importantly, Ruby on Rails lends itself to agile software practices and rapid application development (RAD). Rails is a mature framework that allows programmers to create maintainable software, and it has integrated testing tools that shorten the developer cycle. When you consider the cost of talented programmers (and you know that time is money), reducing development time can mean substantial savings.
Depending on your business development needs, you may be leaning toward PHP or Ruby on Rails. Each has its strengths and weaknesses, but Ruby on Rails continues to gain popularity for business-critical and e-commerce applications because of its versatility, scalability, and upgradability. In the end, you have to consider which language will deliver a cleaner, more stable application that can evolve and grow with your business.
Thanks for reading ❤
If you liked this post, share it with all of your programming buddies!