Search code examples
ruby-on-railsrubyruby-on-rails-4models

Showing two types of "posts" in same view mixed together (Rails)


I have two models...a designs model and products model that are almost identical but they are both nested in different models (one is nested in collection model and the other in assortment model). So to create a product you first have to create an assortment then create the product in the assortment.

I would like to show (in the view) all of the designs and all of the products mixed together sorted by date.

How can I accomplish this? The way I have it now (which is a weak solution) is i have one page that separates the two...but this is tacky and not user friendly.

I know this post is lean and short so if you would like a better explanation, please feel free to ask.


Solution

  • How about something like this:

    things = Design.all.to_a.concat Product.all.to_a
    things.sort! {|t1, t2| t1.date <=> t2.date} #or whatever the date field is called