开发者

How to render multiple models/controllers in one view in ruby on rails

All of the documentation that I have found for RoR shows examples of displaying simple views with one model, for example a post model. But lets say for example, I have several pieces of data I want to display on different sections of a page, what is the best approach to this? If I have a section of "posts", a section of "friends" and lets say a section of "restaurants". All three of these are separate models with separate controllers. Do I need to create a separate con开发者_如何学Ctroller for this page that pulls all of this data together?


Ideally, yes you should create a separate controller. This honestly is less about MVC than it is about using RESTful routes.

What you are describing sounds like a dashboard, and in cases where the controller doesn't really represent a single model or resource, it makes sense to create a one-off controller.

In this case you could create a HomeController or a DashboardController and either set it as your root in routes.rb:

root :to => 'home#index'

Or:

match '/home', :to => 'home#index'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜