标签: 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
实现这一目标的最佳方式是什么?
更新:我对此进行了错误的测试,这确实有效