So I perform a query to the db and I have a complete array of objects:
@attachments = Job.find(1).attachments
Now that I have an array of objects I don't want to perform another db query, but I would like to filter the array based on the Attachment
object's file_type
so that I can have a list of attachments
where the file type is 'logo'
and then another list of attachments
where the file type is 'image'
Something like this:
@logos = @attachments.where("file_type = ?", 'logo')
@images = @attachments.where("file_type = ?", 'image')
But in memory instead of a db query.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…