Paperclip和ActiveRecord:搜索带有附件的对象

时间:2011-10-13 15:08:49

标签: ruby-on-rails activerecord paperclip

在Rails 2.3.6中我有一个用户模型:

class User < ActiveRecord::Base
  has_attached_file :avatar,
                    :styles => {
                      :micro => "32x32#",
                      :thumb => "50x50#",
                      :big_thumb => "80x80#",
                      :small => "220x220>",
                      :featured => "220x220#",
                      :medium => "600x600>"
                    }
end

如何为具有附加头像的用户搜索用户模型?

1 个答案:

答案 0 :(得分:3)

假设您在用户上有一个名为“avatar_file_name”的列,那么

User.scoped({:conditions => 'avatar_file_name IS NOT NULL'})

应该这样做