0
如何寫過濾器在Ruby中的控制器上的Rails上的,也就是eqvivalent這個SQL代碼RoR的過濾器,因爲這SQL
select * from persons where persons.category = 'developers'
如何寫過濾器在Ruby中的控制器上的Rails上的,也就是eqvivalent這個SQL代碼RoR的過濾器,因爲這SQL
select * from persons where persons.category = 'developers'
使用此:
before_filter :nerds_only
private
def nerds_only
@people = Person.where(:category => 'developers')
end
您可能希望考慮創建一個命名範圍,以獲得nerdies:
class Person < ActiveRecord::Base
scope :developers, where(category: 'developers')
end
在你的控制器:
before_filter :developers_only
private
def developers_only
@people = Person.developers
end