I am building a website for a guy. I'm not an experienced developer at all but he's kind enough to let me give it a shot. I want to build a user-less voting system where people don't have to create an account and login to vote and comment on blog articles on his RSS feed. I'm trying to create validations to prevent multiple voting from the same person. Don't know how I would go about doing that. Any ideas are welcome!
Here's my votings controller:
def upvote
@voting = HomeBlog.find(params[:home_blog_id])
@voting.votings.build( :upvote => true, :downvote => false)
@voting.save!
redirect_to request.referrer, notice: "Thanks for the vote!"
end
def downvote
@voting = HomeBlog.find(params[:home_blog_id])
@voting.votings.build( :downvote => true, :upvote => false)
@voting.save!
redirect_to request.referrer, notice: "Thanks for the vote!"
end
The page view:
p id="notice"><%= notice %></p>
<div id="blog-post-show">
<div id="voting-count">
<%= link_to(home_blog_upvote_path(@home_blog.id), {method: :post}, html_options = {})do %>
<%= @home_blog.votings.select { |v| v.upvote == true}.count %><%= image_tag "if_icon-ios7-arrow-up_211690.png" %>
<% end %><br>
<%= link_to(home_blog_downvote_path(@home_blog.id), {method: :post}, id: "downvote") do %>
<%= @home_blog.votings.select { |v| v.downvote == true}.count %><%= image_tag "if_down_1303877.png" %>
<% end %>
</div>
<h3 id="blog-post-show-title">
<b><%= @home_blog.name %> | <%= @home_blog.created_at.to_date %></b>
</h3>
<%= @home_blog.entry.html_safe %>
</div>