rendering multiple controllers to the same layout

12 views
Skip to first unread message

fugee ohu

unread,
Nov 25, 2015, 3:52:54 AM11/25/15
to Ruby on Rails: Talk
I wanna display categories in the side pane and listings in the main, both divisions of the same layout How would I do that?

Colin Law

unread,
Nov 25, 2015, 4:16:57 AM11/25/15
to Ruby on Rails: Talk
On 25 November 2015 at 08:52, fugee ohu <fuge...@gmail.com> wrote:
> I wanna display categories in the side pane and listings in the main, both
> divisions of the same layout How would I do that?

Using CSS probably.

Colin

fugee ohu

unread,
Nov 25, 2015, 4:40:28 AM11/25/15
to Ruby on Rails: Talk

Of course, the listings and categories are related ha ha I wanna show the listings for the category in the main and the sub-categories of that category in the side  Problem is that there's 2 controllers involved, I dunno how to invoke them both to render to the same layout either directly or through partials

(By the way, I have read a rails book, Agile Web Dev ... and I've read  chapters 7-10  from the tutorial you've been referring me to )

Colin Law

unread,
Nov 25, 2015, 6:09:44 AM11/25/15
to Ruby on Rails: Talk
On 25 November 2015 at 09:40, fugee ohu <fuge...@gmail.com> wrote:
> On Wednesday, November 25, 2015 at 4:16:57 AM UTC-5, Colin Law wrote:
>>
>> On 25 November 2015 at 08:52, fugee ohu <fuge...@gmail.com> wrote:
>> > I wanna display categories in the side pane and listings in the main,
>> > both
>> > divisions of the same layout How would I do that?
>>
>> Using CSS probably.
>>
>> Colin
>
>
> Of course, the listings and categories are related ha ha I wanna show the
> listings for the category in the main and the sub-categories of that
> category in the side Problem is that there's 2 controllers involved, I
> dunno how to invoke them both to render to the same layout either directly
> or through partials

You are confused about the MVC model. You can access any model you
like in a controller and setup the data for both panes of the view.
What are the relationships between the various models (categories,
listings, sub-categories or whatever)? Getting those right is
crucial. If Category is a self referential model then it is important
to specify that correctly to save yourself a lot of work. Google for
rails self referential models if you don't know how to do it. If you
find yourself accessing category.parent_id in the code then you are
almost certainly not got it right.

By the way, it would not hurt to say thanks occasionally to those who
try to help you here.

>
> (By the way, I have read a rails book, Agile Web Dev ... and I've read
> chapters 7-10 from the tutorial you've been referring me to )

:)

Colin

fugee ohu

unread,
Nov 25, 2015, 6:59:30 AM11/25/15
to Ruby on Rails: Talk


On Wednesday, November 25, 2015 at 6:09:44 AM UTC-5, Colin Law wrote:
On 25 November 2015 at 09:40, fugee ohu <fuge...@gmail.com> wrote:
> On Wednesday, November 25, 2015 at 4:16:57 AM UTC-5, Colin Law wrote:
>>
>> On 25 November 2015 at 08:52, fugee ohu <fuge...@gmail.com> wrote:
>> > I wanna display categories in the side pane and listings in the main,
>> > both
>> > divisions of the same layout How would I do that?
>>
>> Using CSS probably.
>>
>> Colin
>
>
> Of course, the listings and categories are related ha ha I wanna show the
> listings for the category in the main and the sub-categories of that
> category in the side  Problem is that there's 2 controllers involved, I
> dunno how to invoke them both to render to the same layout either directly
> or through partials

You are confused about the MVC model.  You can access any model you
like in a controller and setup the data for both panes of the view.
What are the relationships between the various models (categories,
listings, sub-categories or whatever)?  Getting those right is
crucial.  If Category is a self referential model then it is important
to specify that correctly to save yourself a lot of work.  Google for
rails self referential models if you don't know how to do it.  If you
find yourself accessing category.parent_id in the code then you are
almost certainly not got it right.

Thanks Colin, I realized that what I needed to do was create a new controller to pull data from both models for combined presentation in views

Colin Law

unread,
Nov 25, 2015, 7:31:24 AM11/25/15
to Ruby on Rails: Talk
Id doesn't need to be a new model, it may be included in (for example)
the categories model if the dual pane view is the normal way to view
categories then put it in that controller.

Colin

fugee ohu

unread,
Nov 25, 2015, 7:41:18 AM11/25/15
to Ruby on Rails: Talk

Id doesn't need to be a new model, it may be included in (for example)
the categories model if the dual pane view is the normal way to view
categories then put it in that controller.

Colin

 What doesn't need to be a new model? I'm gonna have to display listings from multiple categories in the main and children categories of the current category in the side i'm using

Colin Law

unread,
Nov 25, 2015, 8:43:24 AM11/25/15
to Ruby on Rails: Talk
Sorry, I meant it does not need to be a new controller. You said in a
previous post " I realized that what I needed to do was create a new
controller to pull data from both models for combined presentation in
views".

Colin
Reply all
Reply to author
Forward
0 new messages