开发者

Paperclip and ActiveRecord: search for objects with attached files

in Rails 2.3.6 I have a User model:

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

How can I search the User model for users that have an attached avatar?


assuming you have a column named "avatar_file_name" on users then

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

should do it

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜