Layouts - how to render partials from multiple controllers

Richard wrote:

I'm not understand how to piece my whole application together.

Basically I have a home page for a restaurants website which will
display a search facility, a login box, and some stats.

Now my first problem is not knowing which controller this should be the
layout for, because the only part of this page that would be common to
all other pages is the header and that is it: see
http://www.eatnewcastle.com/test/layout.htm

My second problem is that the login box functionality is part of an
account controller, the search box functionality is part of a search
controller etc So how can I render partials from all these different
controllers in this one layout?

I hope this makes sense. Please reply if any aspect is confusing and I
will try to explain myself better. Thanks very much!

The controller is up to you, as its really just personal preference. I usually use the users controller and a "welcome" action for such things. You can call partials from other controllers as such.

render :partial => 'another_controller/partial'

-b

Richard wrote:

Brandt wrote:

render :partial => 'another_controller/partial'

Ah right. Thanks to both of you! This helped. I really didn't realise it was as simple as that.

Will the other controller control the other partial?

Phlip wrote:

Richard wrote:
Brandt wrote:

render :partial => 'another_controller/partial'

Ah right. Thanks to both of you! This helped. I really didn't realise it was as simple as that.
Will the other controller control the other partial?

No, if your partial needs objects, they need to be supplied by the
controller/action that is being performed. Components will achieve
what I believe you are thinking of, but I really can’t comment on them
as I’ve never used them myself.

-b

Brandt wrote:

No, if your partial needs objects, they need to be supplied by the
controller/action that is being performed. Components will achieve what I
believe you are thinking of, but I really can't comment on them as I've
never used them myself.

The moral of the Rails story is that a little bit of MVC is still
much, much better than none!