Class: C80NewsTz::CommentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/c80_news_tz/comments_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#guru

Instance Method Details

#comment_paramsObject



38
39
40
# File 'app/controllers/c80_news_tz/comments_controller.rb', line 38

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

#createObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/c80_news_tz/comments_controller.rb', line 4

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