我有一個場景,我發送通知郵件給所有users.hence我需要得到所有的信息,如useremail,videocount,imagecount,videoids,imageids等和發送給用戶發送郵件。我想通過發送所有必需的參數到這個方法來簡化這個過程,並且再次遍歷每個數組的數組。發送陣列數組作爲參數,然後再次循環雖然每個陣列
for example:-
###########the below code is in a loop of users################
User.signed_in_users.find_in_batches(:batch_size => 100) { |users| users.each { |user|
vcount=Video.where(:users_notified=>f).count
icount=Image.where(:users_notified=>f).count
acount=Audio.where(:users_notified=>f).count
@count << vcount + icount + acount
vcat=###ALL VIDEO CATEGORIES
icat=###ALL IMAGE CATEGORIES
acat=###ALL AUDIO CATEGORIES
@cats << vcat + icat + acat...and many more
###########now sending all these parameter to mailer(array of arrays)
####how i can simplify this call
UserMailer.notify_user(user.email,@video_cat,@video_count,@image_cat,@image_count,@audio_cat,@audio_count,@place_cat,@place_count,@Lpage_count,@Dpage_count).deliver
} } ###loop ends
所有模型和用戶之間是否有任何關係。像一對多? – 2014-09-10 13:51:40
是的,他們有通常的has_many和belongs_to .. @NitinVerma – Milind 2014-09-10 13:52:38