好的,所以我想为所有类型设置一个named_scope,如下所示
class Variety < ActiveRecord::Base
TYPES = ["holiday", "party", "other", yet_another]
Variety::TYPES.each do |role|
define_method
scope "#{role.to_sym}_applications", where(:type => role)
end
end
end
基本上我想要以编程方式定义元的命名范围,这样我就可以做到这一点
Variety.holiday_applications
Variety.party_applications
Variety.other_applications
Variety.yet_another_applications
知道我在定义方法上做错了什么