Skip to content

Instantly share code, notes, and snippets.

@caike
Created January 22, 2011 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caike/790785 to your computer and use it in GitHub Desktop.
Save caike/790785 to your computer and use it in GitHub Desktop.
before_filter
class Admin::TopicsController < ApplicationController
# this could be an example of a before filter
before_filter :check_security_token
def create
topic = Topic.new(params[:topic])
# move this to AR callback before_create ?
topic.started_trending = Time.now
topic.save
render :nothing => true
end
def edit
end
def update
# check_security_token
# updates mentions
end
private
def check_security_token
unless params[:security_token].present? && params[:security_token] == BestPractices::SECURITY_TOKEN
render :nothing => true
end
end
end
class Topic < ActiveRecord::Base
before_create :set_start_trending
scope :trending_top, lambda { |num| where("started_trending > ?", 1.day.ago).order('mentions desc').limit(num) }
private
def set_start_trending
self.started_trending = Time.now
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment