The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Once you get past p. 322 in the book you will start to store the user_id of the voter with each vote. Once you have this you could easily enough search the votes table for all past votes of the user to see if they have an existing vote for the story based on user_id and story_id.

For example you can try something like this:

v = Vote.find_all_by_user_id_and_story_id(1,1)

This should get you all votes for a given user_id and story_id ... if you get an empty array (v.size == 0) you know the person has not voted for this before .... if you get any results at all (v.size > 0) they voted at least once.

This idea is easy enough to test in the Rails Console. Once you have the correct query you can just add some code in the Votes Controller 'create' method to determine if you should add a new vote or you could remove the vote button from the story page to stop them from attempting to vote. Or both for safety ;-)

...and don't EVER try to do this with cookies ... even if you persist the cookie a user can purge the cookies from their browser manually so you can never be sure a missing cookie means someone has/has not done something.

Once you get past p. 322 in the book you will start to store the user_id of the voter with each vote. Once you have this you could easily enough search the votes table for all past votes of the user to see if they have an existing vote for the story based on user_id and story_id.

For example you can try something like this:

v = Vote.find_all_by_user_id_and_story_id(1,1)

This should get you all votes for a given user_id and story_id ... if you get an empty array (v.size == 0) you know the person has not voted for this before .... if you get any results at all (v.size > 0) they voted at least once.

This idea is easy enough to test in the Rails Console. Once you have the correct query you can just add some code in the Votes Controller 'create' method to determine if you should add a new vote or you could remove the vote button from the story page to stop them from attempting to vote. Or both for safety ;-)

...and don't EVER try to do this with cookies ... even if you persist the cookie a user can purge the cookies from their browser manually so you can never be sure a missing cookie means someone has/has not done something.

This seems to be the best way to limit the voting. I don't think limiting the votes by IP address really helps solve the problem.

How would it be possible to modify the votes controller create action to prevent a user from voting on a story more than once?