I'm trying to allow users to vote on threads without having to sign in/up in order to increase user engagement. How do I do this? At the moment my current though process is to tie votes with the visitor's IP address in order to prevent multiple votes, though another issue is that request.remote_ip is not getting me the correct IP (I'm on a school network). Any suggestions? Thanks very much!
Vote action in Threads Controller
def upvote
@thread = Thread.find(params[:id])
current_user.up_vote(@thread)
flash[:message] = 'Thanks for voting!'
respond_to do |format|
format.html { redirect_to :back }
format.js
end
Vote routes
resources :threads do
member do
post :upvote
post :unvote
end
I wrote acts as votable.
The whole idea behind this gem was to allow anything to vote on anything (so there is not hard dependency on a user, like in the situation you are describing).
If you do not want to use IP addresses to store votes then maybe you can use a unique ID that you tie to each session. This would be open to vote fraud, but it would allow anyone to vote without having an account.
You could do something like
session[:voting_id] ||= create_unique_voting_id
voter = VotingSession.find_or_create_by_unique_voting_id(session[:voting_id])
voter.likes @thread
You would need to setup a VotingSession model that acts_as_voter and maintains a unique voting id, but that should be really easy w/ rails.
Hope this helps