ruby on rails - if I have 2 models can I sort them both at once? -


let's have image model , video model how can display them both in index date

i going take torch here. :) sergio means this:

class media < activerecord::base   belongs_to :image   belongs_to :video end 

then can sort/filter/paginate easily

@media = media.where('created_at > ?', 2.days.ago).order(:id) 

just don't forget create corresponding media record when add new image/video

image = ... media.create(image: image) 

Comments

Popular posts from this blog

cron - how to properly run Python script with crontab on every system startup -

elasticsearch - Is the order of operations guaranteed in a bulk update? -

Slow performance first queries on SQL Azure -