Sha256: f715259f456294c85014cbd25af6c4d7a8ae4c457150818c9725b9d394bc84d3
Contents?: true
Size: 1.48 KB
Versions: 2
Compression:
Stored size: 1.48 KB
Contents
module C80NewsTz class CommentsController < ApplicationController before_action :check_comments_enabled 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 private def comment_params params.require(:comment).permit(:message, :user_id, :fact_id, :r_blurb_id) end def update_user_last_comment(user) user.last_comment_ts = Time.now.to_i user.save end def check_comments_enabled comments_enabled = CommentsProps.find(1).comments_enabled unless comments_enabled respond_to do |format| format.js { render :action => 'comments_disabled' } end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
c80_news_tz-0.1.1.26 | app/controllers/c80_news_tz/comments_controller.rb |
c80_news_tz-0.1.1.25 | app/controllers/c80_news_tz/comments_controller.rb |