Ways to share code among the 'layout'


#1

Is there a way to use the same code accross multiple layouts. Normally,
I am associating a layout with a particular controller? Is there a
cleaner way.


Berlin B.
(ramaza3 on freenode)
http://www.newspiritcompany.com
http://www.newspiritcompany.com/newforums
also checkout alpha version of botverse:
http://www.newspiritcompany.com:8086/universe_home


#2

Berlin B. wrote:

Is there a way to use the same code accross multiple layouts. Normally,
I am associating a layout with a particular controller? Is there a
cleaner way.

Hmm, do you mean to use the same layout for more controllers? (Or what
do you mean by ‘code’?) If yes:

  1. For the whole application:
    Call your default layout ‘application.rhtml’

  2. For some controllers:
    If your layout you would like to use more times is here:
    ‘app/views/layouts/foolayout.rhtml’
    You can use them int controllers like this:

class BarController < ApplicationController
layout “foo”

class BazController < ApplicationController
layout “foo”

etc.

2b) Alternatively, if you would like to use this layout for the whole
application, you can put it here:

class ApplicationController < ActionController::Base
layout “foolayout”
end

Normally, I am associating a layout with a particular controller?
If you want a specific behaviour, yes. If you do not want a layout or
you have specified one for the entire app as stated in 1) or 2b), and
would like to use that, no.

Cheers,
Peter