Ruby on Rails - IP Limit

I'm new to rails, so easy. I created a blog with the ability to "vote" for a post using a feature similar to Facebook. I do not use authentication, but I want to limit the voting at a specific post by IP. That is, as soon as someone votes for a message, they cannot vote again (unless they reset their router, of course).

I feel that it must be something that I touch upon, changing the voices or messages of the Model, but I am afraid that it is connected with Sessions, which ... I have no experience yet.

Let me know if you need me to post any code. Here is the voice controller.

class VotesController < ApplicationController

  def create
    @post = Post.find(params[:post_id])
    @vote = @post.votes.create!(params[:vote])

       respond_to do |format|
       format.html { redirect_to @post}
       format.js
     end
  end
end
+3
3

, , . IP- .

  • .

    class Vote < ActiveRecord::Base
      validates_uniqueness_of :ip_address
      ...
    end
    
  • class VotesConroller < ApplicationController
      ...
      def create
        unless Vote.find_by_post_id_and_ip_address(params[:post_id],request.remote_ip)
           posts.votes.create!(params[:vote].update({:ip_address => request.remote_ip}))
        end
      end
    end
    
+8

EmFi, bensie IP- , IP-, , - (, - http://proxy.org/).

, , , , .

+1

ip_address votes validates_uniqueness_of :ip_address, , IP .

0

Source: https://habr.com/ru/post/1723479/


All Articles