ruby on rails - Sending arrays of arrays as parameter and then again looping though each array -


i have scenario sending notification mail users.hence need info such useremail,videocount,imagecount,videoids,imageids etc , send usermailer send mail.i want simplify process sending required parameters method , again looping through each array of arrays.

    example:-      ###########the below code in 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 these parameter mailer(array of arrays)    ####how can simplify 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 

i don't know why trying fetch same value multiple time. below code running multiple time without reason.

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 

because iterating on user object. , there no interaction of user in bunch of code. can take out of each block:

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  user.signed_in_users.find_in_batches(:batch_size => 100 ) { |users| users.each { |user|   ###########now sending these parameter mailer(array of arrays)   usermailer.notify_user(user.email,@count,@cats)  } } ###loop ends 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -