How to show two models output in one page

Hi,

I have two models post and video. How to combine their outputs and show it in a one page.

Regards
Suji A.

There are numerous ways you could achieve it. Can you give more details for your particular needs ?

Are the two models related ?

Thanks & Regards,
Dhruva Sagar.

No the models not related. Just i create 1 application and create post,video models inside it,the post model contains the title, content and the video model contains the title,description,video file. i want to show the title,content of the post model and the video in one page.

Regards,
Suji A.

Hi,

Obviously you can still have the post & the video content on the same page.

But can you then explain the scenario that your trying to create ?

For instance which video would you want to show in which post ? Logically it implies that they should be related and in the page where you display the POST you should be displaying the appropriate video that is related to that post…

But in any case the relationship is not mandatory, if you still wish to show both the post data as well as the video data on the same page, then you can do that too.

Assuming that your checking out the POST INDEX action you could have something like this in the index action of the POST controller :

def index

@posts = Post.all

@videos = Video.all

end

and in the view you can then loop through these 2 models and display their content as you like…

Thanks & Regards,
Dhruva Sagar.

Thank you sir, i got some idea from this. Hereafter i can implement it in my application.

The scenario for this is , i have to create one application that should have three part in a one page, in that the first part will show the recent post and the second part will show the video and the third part will show the older posts links. The post and the video are not dependent.

Regards,
Suji A.