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

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -