2

I want to be able to vote on my links without having to login through something like devise or other authentication system. I have devised installed on my application and it's up and running and works fine. But I don't want the user to have to be logged in to vote. I was thinking doing it through the IP Address and would be thankful if someone can help me through this process.

I want to clarify that I can vote without problem when I am logged in.

This is how my links_controller#upvote looks like:

def upvote
  @link = Link.find(find_link)
  respond_to do |format|
  unless current_user.voted_for? @link
    format.html { redirect_to :back }
    format.json { head :no_content }
    format.js { render :layout => false }
    @link.cached_votes_total = @link.cached_votes_total + 1
    @link.save
    @link.upvote_by current_user
  else
    flash[:danger] = 'You allready voted this entry'
    format.html { redirect_to :back }
    format.json { head :no_content }
    format.js
  end
 end
end

link.rb

acts_as_votable

user.rb (using devise)

acts_as_voter
  • 1
    IP addresses cannot safely be used as identifier. You need authentication. – SLaks May 10 '16 at 22:25
  • There is multiple websites that use this technique. So it's possible. – Daniel Webb May 10 '16 at 22:29
  • It's a horrible idea. IPs are often shared by many people (sometimes entire cities or countries), and mobile devices can change IPs frequently. – SLaks May 10 '16 at 22:32
  • Okay, thanks for insight! Is there any other way to do it without having to login? – Daniel Webb May 10 '16 at 22:37
  • Depending on what you actually want, even logins won't help. How will you prevent people from logging in with two different accounts? – SLaks May 10 '16 at 22:47
  • "There is multiple websites that use this technique. So it's possible." Name 6 – ruby_newbie May 10 '16 at 22:47
  • You can't really prevent people from voting multiple times, you can only make it harder, with authentication people will just create multiple accounts, with ip verification people will use multiple devices, proxies, vpn, tor or just reconnect for those who still have a dynamic ip. The thing is IP verification is not only inefficient against multivoters but it will block legitimate voters who have no choice but to share an ip. – ivann May 11 '16 at 20:38

0 Answers0