Reputation: 6906
I've built several apps in rails that have submissions that you can vote on. Vote up or vote down. I've always custom built the voting functionality, and with each app, the code has gotten better and more elegant. But one part that has always been the same is when a user comes to a submission, I do the same thing in the view:
<% if @submission.votes.include?(current_user.votes) %>
"already voted on"
<% else %>
<%= link_to "vote", submission_vote_path(@submission) %>
<% end %>
Or something of this nature. I have a feeling there must be a more efficient way to go about this, but I'm not exactly sure how. Any advice?
Upvotes: 0
Views: 40
Reputation: 115541
It looks fine, but obviously it depends on the queries lying behing the scene.
It's always better to consume ruby code than db queries.
So if you have to check many votes, stick with your current code. Otherwise, make a dedicated query.
Upvotes: 1