Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8481285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:31:30+00:00 2026-06-10T19:31:30+00:00

in this screencast Ryan Bates showed how to implement reputation system from scratch. But

  • 0

in this screencast Ryan Bates showed how to implement reputation system from scratch. But is there any way to give the current_user only 1 vote, and check whether user has already voted for application, and if yes, restrict the possibility of voting?

I think something like this in user.rb should work, but I don’t know ho to exactly write it

   def has_one_vote
      Restrict amount of user votes to 1
   end

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:31:32+00:00Added an answer on June 10, 2026 at 7:31 pm

    I’m assuming you have Users, Votes, and Posts, and that users vote on posts.

    You should add a uniqueness validator to the Vote class on the user_id attribute, scoped to the post_id. This limits the number of votes a user can have on a given post to one:

    class Vote
      belongs_to :user
      belongs_to :post
    
      validates :user_id, uniquness: { scope: :post_id }
    end
    

    To limit the total number of votes a user can ever create, either remove the scope from the uniqueness validator, or (more correctly) move the foreign key into the users table.

    That is, either this:

    class Vote
      belongs_to :user
      belongs_to :post
      validates :user_id, uniquness: true
    end
    

    or this:

    class User
      belongs_to :vote
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I'm currently on Day 2 of Jeffrey Way's Codeigniter tutorial. In this screencast
I've just implemented OmniAuth (using Ryan Bates' Screencast http://asciicasts.com/episodes/235-omniauth-part-1 ) and am writing Rspec
The important differences are covered in this screencast, but I am looking for a
Is it possible to use the method in Ryan Bates recent screencast to create
I have an example gem as from the Ryan screencast It contains additional file
I followed this screencast to make a erb:to:haml rake task: http://teachmetocode.com/screencasts/creating-a-rake-task-to-convert-erb-to-haml/ I backed everything
I'm trying to use the T4 templates in my MVC project. This screencast suggests
On this screencast , at time 16:15, Paul Nielsen talks about displaying data as
The author in this screencast is using jquery to submit data to a database
I saw this on a screencast and couldn't figure out what it was. Reference

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.