One Vote Per Session

I have an app where any user (no login required) can vote on something
and I need a way to limit them to one vote per session. Does anyone have
any suggestions?

Thanks a lot for any help you can offer.

On Jan 18, 2008 9:15 AM, Aaron J.
[email protected] wrote:

I have an app where any user (no login required) can vote on something
and I need a way to limit them to one vote per session. Does anyone have
any suggestions?

If you use activerecord sessions (you should be doing that) you can
have a session model and save the vote with a session_id.

The thing is that you are going to prune the sessions table (you
should be doing that too) and they are going to be nullified, but if
you keep sessions for 2 weeks is not a problem having votes without a
session assigned.

Disclaimer: i haven’t done anything like this but i think it may for
you.

Off the top of my head:

class VoteManager

def initialize(session)
@session = session
end

def submit(*args)
unless @session[:voted]
vote = Vote.create!(*args)
@session[:voted] = true
vote
end
end
end

in controller

vote_manager = Vote.new(session)
vote_manager.submit(params[:vote]) # will return nil if voted before

On Jan 18, 4:15 am, Aaron J. [email protected]

On 18 Jan 2008, at 14:21, Emilio T. wrote:

should be doing that too) and they are going to be nullified, but if
you keep sessions for 2 weeks is not a problem having votes without a
session assigned.

Online voting is fundamentally flawed (sessions/cookies can be
circumvented, everything can be actually), but i’ve been using a
combination of sessionbased, cookiebased and ip based filtering.

Best regards

Peter De Berdt

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs