Sha256: 42410c943c3485a60dbdbc193041562c06fb00b7021a367a0fcc917f11297fe6

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

module C80NewsTz
  class CommentsController < ApplicationController

    def create

      mark_spam = false
      time_delta = 0
      user = User.find(params[:comment][:user_id])

      # проверим, не спамер ли это?
      unless user.last_comment_ts.nil?
        time_delta = Time.now.to_i - user.last_comment_ts
        mark_spam = time_delta < 30
      end

      if mark_spam
        respond_to do |format|
          @time_elapsed = 30 - time_delta
          format.js { render :action => 'antispam' }
        end
      else
        @comment = Comment.create(comment_params)
        if @comment.save
          update_user_last_comment(user)
          @comments_count = @comment.blurb_or_fact.comments.count
          respond_to do |format|
            format.js { render :action => 'created'}
          end
        else
          respond_to do |format|
            format.js { render :json => @comment.errors }
          end
        end
      end

    end

    def comment_params
      params.require(:comment).permit(:message, :user_id, :fact_id, :r_blurb_id)
    end

    private

    def update_user_last_comment(user)
      user.last_comment_ts = Time.now.to_i
      user.save
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
c80_news_tz-0.1.1.24 app/controllers/c80_news_tz/comments_controller.rb