Topic: putting views in main layout

Hello

I am spending time with putting views to other layout.
So I want to insert "categories" views to "main" layout.

In categories controller I was set layout 'main', but now I don't know how to
call this view in that layout and I don't know how to write function for this ..

Re: putting views in main layout

Are you talking about including a view from another controller? You can use partials for that.

<%= render :partial => 'categories/listing' %>

Rails will then look for a file called _listing.rhtml in the app/views/categories directory and include it.

vinnie - rails forum admin

Re: putting views in main layout

I did that, but then application tell error:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.each


Then I inserted function listning to main controller, but it is still telling errors.
Now I don't know how controllers communicate with others models..
or what I must do now

Last edited by blmahoric (2006-09-14 13:03:02)

Re: putting views in main layout

When you include a partial from another controller, you'll have to make sure to setup the instance variables expected in the partial.

Typically this means you'll end up moving a lot of before filter style loads up to the ApplicationController or some subclass, if you have partials shared by many controllers -- ie a sidebar shopping cart that gets displayed everywhere, or similar type things.

My RoR journey  -- thoughts on learning RoR and lessons learned in applying TDD and agile practices.

Re: putting views in main layout

I was also facing this same problem and NielsenE is right I managed it the same way. it works. Thanks all of you.