Created
January 22, 2011 02:12
-
-
Save caike/790785 to your computer and use it in GitHub Desktop.
before_filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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