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

many to many - Django Rest Framework ManyToMany filter multiple values -

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

Java Entity Manager - JSON reader was expecting a value but found 'db' -