2012-06-01 38 views

回答

3

使用此:

before_filter :nerds_only 

private 

def nerds_only 
    @people = Person.where(:category => 'developers') 
end 
3

您可能希望考慮創建一個命名範圍,以獲得nerdies:

class Person < ActiveRecord::Base 
    scope :developers, where(category: 'developers') 
end 

在你的控制器:

before_filter :developers_only 

private 

def developers_only 
    @people = Person.developers 
end