I have a rails app that uses voting. Right now I have it set up so
that you can vote on a word, but it doesn't limit the number of votes.
So someone can vote on the same word more than once.
How do I make it so that you can only vote once on a word. Some
methods I've found online included checking for a unique ip address
but that can bring problems for people at work or places with block ip
addresses.
I was thinking that I would have to using session cookies or something
like that. But I'm new to RoR and don't know where to start.
Here is my current code:
# CONTROLLER
class VotesController < ApplicationController
def create
@word = Word.find(params[:word_id])
@word.votes.create(:user => @current_user)
respond_to do |format|
format.html { redirect_to @word }
format.js
end
end
end
# MODEL
class Vote < ActiveRecord::Base
belongs_to :word, :counter_cache => true
belongs_to :user
end
# VIEWS
# Create.js.rs
page.replace_html 'vote_score', "Score: [EMAIL PROTECTED]"
page[:vote_score].visual_effect :highlight, :duration => 2.0
page[:vote_score].visual_effect :pulsate, :duration =>
1.5, :collection => @word.votes.latest
#Edit.rjs
page.replace_html 'vote_score', "Score: [EMAIL PROTECTED]"
page[:vote_score].visual_effect :highlight, :duration => 2.0
page[:vote_score].visual_effect :pulsate, :duration => 1.5
#Vote.html.erb
<li><%= vote.created_at.to_formatted_s(:short) %></li>
I would appreciate some help with figuring this out.
Thanks in advance.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---