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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Jennings <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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? > > Thanks a lot for any help you can offer. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 18, 2008 9:15 AM, Aaron Jennings <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 18 Jan 2008, at 14:21, Emilio Tagua 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.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 --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---