I would like for visitors to only be able to vote on each link once. I understand that if they clear their cookies, they’ll be able to vote again. How would I implement this feature in rails? I’ve attached my files below. Thanks
Controller https://gist.github.com/1274274
I would not recommend doing it that way but if you insist I would say you should create a hash with the ids of the link as keys and their values set to true or false according to the type of vote.
I would change your controller like this:
This logic should belong to the model but we shouldn’t access the session variable inside the model. You can refactor this code inside the model and just pass the session to it from the controller. It would be something like this:
Find more about sessions here:
http://guides.rubyonrails.org/action_controller_overview.html#session
Hope that works.