##65 Stopping Spam with Akismet
# comments_controller.rb
def create
  @comment = Comment.new(params[:comment])
  @comment.request = request
  if @comment.save
    if @comment.approved?
      flash[:notice] = "Thanks for the comment."
    else
      flash[:error] = "Unfortunately this comment is considered spam by Akismet. " + 
                      "It will show up once it has been approved by the administrator."
    end
    redirect_to episode_path(@comment.episode_id)
  else
    render :action => 'new'
  end
end
def destroy_multiple
  Comment.destroy(params[:comment_ids])
  flash[:notice] = "Successfully destroyed comments."
  redirect_to comments_path
end
def approve
  @comment = Comment.find(params[:id])
  @comment.mark_as_ham!
  redirect_to comments_path
end
def reject
  @comment = Comment.find(params[:id])
  @comment.mark_as_spam!
  redirect_to comments_path
end
# models/comment.rb
before_create :check_for_spam
def request=(request)
  self.user_ip    = request.remote_ip
  self.user_agent = request.env['HTTP_USER_AGENT']
  self.referrer   = request.env['HTTP_REFERER']
end
def check_for_spam
  self.approved = !Akismetor.spam?(akismet_attributes)
  true # return true so it doesn't stop save
end
def akismet_attributes
  {
    :key                  => 'abc123',
    :blog                 => 'http://railscasts.com',
    :user_ip              => user_ip,
    :user_agent           => user_agent,
    :comment_author       => name,
    :comment_author_email => email,
    :comment_author_url   => site_url,
    :comment_content      => content
  }
end
def mark_as_spam!
  update_attribute(:approved, false)
  Akismetor.submit_spam(akismet_attributes)
end
def mark_as_ham!
  update_attribute(:approved, true)
  Akismetor.submit_ham(akismet_attributes)
end
                이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Fortinet FortiWeb Web Application Firewall Policy BypassFrom: Geffrey Velasquez Date: Wed, 2 May 2012 20:33:23 -0500...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.