diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 983881c..9b96659 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -26,6 +26,20 @@ class CommentsController < ApplicationController comment.thread_id = Keystore.incremented_value_for("thread_id") end + # prevent double-clicks of the post button + if !params[:preview].present? && + (pc = Comment.find_by_story_id_and_user_id_and_parent_comment_id(story.id, + @user.id, comment.parent_comment_id)) + if (Time.now - pc.created_at) < 5.minutes + comment.errors.add(:comment, "^You have already posted a comment " << + "here recently.") + + return render :partial => "commentbox", :layout => false, + :content_type => "text/html", :locals => { :story => story, + :comment => comment } + end + end + if comment.valid? && !params[:preview].present? && comment.save comment.current_vote = { :vote => 1 } diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e90277c..7600b91 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2,11 +2,11 @@ module ApplicationHelper def errors_for(object, message=nil) html = "" unless object.errors.blank? - html << "
- <%= render :partial => "comments/comment", - :locals => { :comment => show_comment, :story => story } %> -
- <% else %> - <%= errors_for comment %> - <% end %> +<% if defined?(show_comment) && show_comment.valid? %> ++ <%= render :partial => "comments/comment", + :locals => { :comment => show_comment, :story => story } %> +
<% end %>