Forum: Ruby on Rails Ways to share code among the 'layout'

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Berlin B. (Guest)
on 2006-05-04 12:37
(Received via mailing list)
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
Peter S. (Guest)
on 2006-05-04 13:23
(Received via mailing list)
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
This topic is locked and can not be replied to.