nested layouts??? whole site layout + controller layout???

Have a look at content_for.

Rails API: http://rails.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html

Example from the layout's perspective: http://thoughts.pjhyett.com/day/46#thought-113

Tks - I’ve got content_for working ok. I can use a layout for the overall header/footer and nav/content area layout. In this layout file then:
a) In the Navigation area I use: <%= yield :navigation_content %> and

b) In the content area I use: <%= @content_for_layout %>

Within each of a controller view I use <%= render :partial => ‘contact_navigation’ %> as I have to put this in each of the views for a given controller. This way I can put the actual controller specific navigation in a file such as _contact_navigation.rhtml.

The only problem here is that one has to put the an entry such as <%= render :partial => ‘contact_navigation’ %> in EACH of the views in that controller area. It would be beter to have this automatically occur, which I guess is getting back to the concept of having a layout at the controller level too. So a layout (controller specific) within a layout (the overall site layout).

Is there a way to achieve this? (given that layouts within layouts don’t seem to work)

Greg

b) In the content area I use: <%= @content_for_layout %>

You can just use 'yield' with no arguments. No need for @content_for_layout.

Is there a way to achieve this? (given that layouts within layouts don't seem to work)

<%= render :partial => (controller.controller_name + '/contact_navigation') %> ?

Consider using render :file, as well, if content_for isn't doing what you want.

Chris - I guess what I’m after is a way to handle the navigation pane without having to put knowledge of this (or any additional lines) into each of controllers view files, i.e. don’t want to have to put something into list.rhtml
, new.rhtml, edit.rhtml, show.rhtml each time (i.e. number of controllers x about 4-5).

Seeing I’m already using the rails layout concept for my overall site specific header/footer layout, to do what I want I guess I need a way to inject a “layout” like concept in the controller itself, for example in contact.rb (i.e. I guess I’m trying not to have to modify the outcome of the rails scaffold generated views etc). Would any of the ideas you were suggested be able to do this?

PS - Just come across this (http://gridpt1.fe.up.pt/mlopes/blog/index.php/2006/08/12/nested-layouts-in-ruby-on-rails/). I’ll have to digest this as the intro at least seems to be acknowledging the problem and desire to do what I was asking for

That looks like a good technique for what you want to do. I just tried
it on my app but i get an undefined method error...
ActionView::TemplateError (undefined method `inside_layout' for
#<#<Class:0x32205cc>:0x32205a4>) on line #1 of
app/views/layouts/store.rhtml:

Weird. The method is definitely defined and required in the environment...

Sean

Oops, that was just my mistake... I had omitted the last couple of
lines to be included in environment.rb.... The method works perfectly
now and has saved me from rendering the same partial about 20
times....

Sean

Perhaps this should be incorporated into rails itself. What do you think? From my perspective it should.

Got the layout within layout concept working (i.e. http://gridpt1.fe.up.pt/mlopes/blog/index.php/2006/08/12/nested-layouts-in-ruby-on-rails/
)

I’ve realised what I also really want to to be able to:

a) define the DIV based layout in the overall rails layout (e.g. defines where the left side navigation is, as well as header/footer/content)

b) populate the navigation area on a controller specific basis, but without the individual view pages having to have anything to do with this.

I think I could do this using “content_for” (
http://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html#M000528) however I really need to be able to set the instance variable within the controller. I’ve tried this but no luck yet (still new to ruby).

Anyone suggest where I’m going wrong here?

contacts_controller.rb