rating - Prevent users from voting multiple times in Rails -
I have a simple rating system setup in a blog model, I use a custom method to increase ratings, Which blog is an integer in DB.
def increase @ post = post.find (params [: id]). Increment! (: Rating) if logged_in? Current Flash [: Notice] = "Thanks for rating" redirect_to posts_url end
Now, I can vote as often as I want, certainly a recipe for disaster many users Bar can vote and can drive in a number of ways.
How do I make it so that the vote deposit button once went after depositing it. I had the idea of creating a different model for rating and using a custom token, but it seems to be useless for a simple app.
Any help?
Senthil
One way to do this will be your post model and rated post model. In the rated post model there may be information such as incremented: boolean
, subtraction: boolean
, changed_b: integer (user_id)
, post_id: integer
.
You can then identify when RatedPost.find_by_post_id_and_changed_by (post.id, user.id)
returns any records.
You can also recognize if the points were increased or decreased, in this way you can allow a user to change his vote for a certain time (vote 24 hours).
Comments
Post a Comment