Displaying two different data sets at the same time

Thanks to some help from earlier posters, I’ve been moving along with my
test application. I did run into one more stumbling block, though.

Say I have two sets of headlines, news and sports, the table structures
are slightly different but each has a headline, writer and date.

In the controller:
@news = News.find(:all)
@sports = Sports.find(:all)

Getting they to display like this isn’t a problem.

News
News Headline 1 - Writer 08-01-2008
News Headline 2- Writer 07-31-2008
News Headline 3- Writer 06-05-2008

Sports
Sports Headline 1- Writer 07-30-2008
Sports Headline 2- Writer 06-16-2008

My question is this:
How do you structure the loop to go through both arrays and display
based on date so that the result could be two, intertwined lists.
Example:

News Headline 1 - Writer 08-01-2008
News Headline 2 - Writer 07-31-2008
Sports Headline 1 - Writer 07-30-2008
Sports Headline 2 - Writer 06-16-2008
News Headline 3 - Writer 06-05-2008

Any help or starting points would be sincerely appreciated.

Elliot C. wrote:

My question is this:
How do you structure the loop to go through both arrays and display
based on date so that the result could be two, intertwined lists.
Example:

News Headline 1 - Writer 08-01-2008
News Headline 2 - Writer 07-31-2008
Sports Headline 1 - Writer 07-30-2008
Sports Headline 2 - Writer 06-16-2008
News Headline 3 - Writer 06-05-2008

Any help or starting points would be sincerely appreciated.

you could use polymorphic associations?
http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html

your class definitions might look lke
class Article < ActiveRecord::Base
belongs_to :content, :polymorphic =>
end
class News < ActiveRecord::Base
has_one :article, as => :content
end
class Sports < ActiveRecord::Base
has_one :article, as => :content
end

Also, refer to Polymorphic Associations section in Chapter 18.4 Joining
to Multiple Tables of Agile Web D. with Rails (third edition).
If you dont have this book, i HIGHLY recommend you get it from

aa aa wrote:
slight typo, missed the "true

class Article < ActiveRecord::Base
belongs_to :content, :polymorphic => true
end
class News < ActiveRecord::Base
has_one :article, as => :content
end
class Sports < ActiveRecord::Base
has_one :article, as => :content
end