从rails3中的数组声明范围

时间:2013-02-19 22:40:24

标签: ruby-on-rails ruby-on-rails-3 rails-activerecord scopes

我有一个符号数组,我想在每个ActiveRecord模型中声明一个范围。

以下不起作用:

@@animal_types = [:horse, :cat, :dog]
@@animal_types.each do |a|
    scope a, :conditions => "animal_type = '#{a.to_s}'"
end

实现这一目标的最佳方式是什么?

更新:我对此进行了错误的测试,这确实有效

0 个答案:

没有答案