Paperclip and ActiveRecord: search for objects with attached files
in Rails 2.3.6 I have a User model:
开发者_StackOverflowclass 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
精彩评论