开发者

Paperclip and ActiveRecord: search for objects with attached files

开发者 https://www.devze.com 2023-04-13 07:25 出处:网络
in Rails 2.3.6 I have a User model:开发者_StackOverflow class User < ActiveRecord::Base has_attached_file :avatar,

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

精彩评论

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

关注公众号