T
T
Tesla_Rails2014-02-05 21:32:07
Ruby on Rails
Tesla_Rails, 2014-02-05 21:32:07

How can you make the "like" action only run once per user in Rails?

Started learning Rails. Now I'm making a news site and there was one question about voting for an article. How can I make the "like" action only run once per user.

def like
   @article = Article.find(params[:id])   
   @article.increment!(:votes_count)
   redirect_to action: :show
end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sl_bug, 2014-02-05
@Tesla_Rails

Keep information about which user voted for what. Then check in this action.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question