Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 756047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:12:01+00:00 2026-05-14T15:12:01+00:00

I have made a simple Rails application that allows people to comment on posts.

  • 0

I have made a simple Rails application that allows people to comment on posts. How do I prevent that user from submitting that form over and over again? On reddit.com they only allow newer users to make new posts every ten minutes. How can I do this with my simple blog/commenting system? Any help would be greatly appreciated. Thanks for reading my question.
EDIT: I’m trying to accomplish this without a user model.

Here’s my current Comments controller:

class CommentsController < ApplicationController
  # before_filter :require_user, :only => [:index, :show, :new, :edit]

  before_filter :post_check

  def record_post_time
    cookies[:last_post_at] = Time.now.to_i
  end

  def last_post_time
    Time.at((cookies[:last_post_at].to_i rescue 0))       
  end

  MIN_POST_TIME = 2.minutes

  def post_check
    return true if  (Time.now - last_post_time) > MIN_POST_TIME

    # handle error
    # flash("Too many posts")
  end

  def index
    @message = Message.find(params[:message_id])
    @comments = @message.comments
  end

  def show
    @message = Message.find(params[:message_id])
    @comment = @message.comments.find(params[:id])
  end

  def new
    @message = Message.find(params[:message_id])
    @comment = @message.comments.build
  end

  def edit
    @message = Message.find(params[:message_id])
    @comment = @message.comments.find(params[:id])
  end

  def create
    @message = Message.find(params[:message_id])
    @comment = @message.comments.build(params[:comment])
    #@comment = Comment.new(params[:comment])
    if @comment.save
      record_post_time#
      flash[:notice] = "Replied to \"#{@message.title}\""
      redirect_to(@message)
      # redirect_to post_comment_url(@post, @comment) # old
    else
      render :action => "new"
    end
  end

  def update
    @message = Message.find(params[:message_id])
    @comment = Comment.find(params[:id])
    if @comment.update_attributes(params[:comment])
      record_post_time
      redirect_to post_comment_url(@message, @comment)
    else
      render :action => "edit"
    end  
  end

  def destroy

  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:12:02+00:00Added an answer on May 14, 2026 at 3:12 pm

    Try this:

    class CommentsController < ApplicationController
    before_filter :post_check        
    def record_post_time
      cookies[:last_post_at] = Time.now.to_i
    end
    def last_post_time
      Time.at((cookies[:last_post_at].to_i rescue 0))       
    end    
    MIN_POST_TIME = 2.minutes    
    def post_check
      return true if  (Time.now - last_post_time) > MIN_POST_TIME
      flash[:notice] = "Too many comments makes you a busy cat!"
      @message = Message.find(params[:message_id])
      redirect_to(@message)
      return false
    end
    def create
      @comment = Comment.new(params[:comment])
      if @comment.save
        record_post_time
      else
      end
    end
    
    def update
      @comment = Comment.find(parms[:id])
      if @comment.update_attributes(params[:comment]))
        record_post_time
      else
      end
    end    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started using jQuery and rails. I have made a simple form that
I have a simple software that is made in Delphi 7, and it crashes
Heavy emphasis on simple. I've never made an installer and I'd rather not have
I have made a SVG image, or more like mini application, for viewing graphs
I have made a custom UserControl i Vb.net (windows application). How can I add
I have made a little app for signing up for an event. User input
So I have made a webservice that interfaces with a set of data contained
I have made some code which exports some details of a journal article to
I have made a program in c and wanted to see, how much memory
I have made a new windows service which works fine using barebone code (just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.