I''d like a controller to use a specific layout for all its views. Right now I''m calling `render :layout => ''foo''` in each method, but there must be a better way. I tried class Users < Application layout ''foo'' end And that definitely doesn''t work. Then, as a test, I tried setting _layout within a method, like this: def index _layout = ''foo'' render end And that changes _layout successfully, but Merb still picks the same layout (''application''). There''s a line in lib/merb/mixins/render.rb that seems to pick the layout to use: 133: def render(*args,&blk) 134: opts = (Hash === args.last) ? args.pop : {} 135: 136: action = opts[:action] || params[:action] 137: opts[:layout] ||= _layout And since I didn''t pass anything for args, it should use the _layout I''ve set, right? Yet it doesn''t. So, anyone know how I can specify a controller''s layout?
self._layout = "foo" seems to work. Yeah, I found it by trial and error and by reading the source of Merb... My first impression about Merb : it''s a little "bare metal" for the moment, my Rails habits saves me from time to time but I''m very slow at programming something with Merb ATM. But, the future seems bright :) ++ yk 2008/1/13, Christian von Kleist <cvonkleist at gmail.com>:> I''d like a controller to use a specific layout for all its views. > Right now I''m calling `render :layout => ''foo''` in each method, but > there must be a better way. I tried > > class Users < Application > layout ''foo'' > end > > And that definitely doesn''t work. Then, as a test, I tried setting > _layout within a method, like this: > > def index > _layout = ''foo'' > render > end > > And that changes _layout successfully, but Merb still picks the same > layout (''application''). There''s a line in lib/merb/mixins/render.rb > that seems to pick the layout to use: > > 133: def render(*args,&blk) > 134: opts = (Hash === args.last) ? args.pop : {} > 135: > 136: action = opts[:action] || params[:action] > 137: opts[:layout] ||= _layout > > And since I didn''t pass anything for args, it should use the _layout > I''ve set, right? Yet it doesn''t. > > So, anyone know how I can specify a controller''s layout? > _______________________________________________ > Merb-devel mailing list > Merb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/merb-devel >
> self._layout = "foo" > seems to work. Yeah, I found it by trial and error and by reading the > source of Merb... > > My first impression about Merb : it''s a little "bare metal" for the > moment, my Rails habits saves me from time to time but I''m very slow > at programming something with Merb ATM. But, the future seems bright > :) > > ++ > > yk > > 2008/1/13, Christian von Kleist <cvonkleist at gmail.com>: > > > I''d like a controller to use a specific layout for all its views. > > Right now I''m calling `render :layout => ''foo''` in each method, but > > there must be a better way. I tried > > > > class Users < Application > > layout ''foo'' > > end > > > > And that definitely doesn''t work. Then, as a test, I tried setting > > _layout within a method, like this: > > > > def index > > _layout = ''foo'' > > render > > end > > > > And that changes _layout successfully, but Merb still picks the same > > layout (''application''). There''s a line in lib/merb/mixins/render.rb > > that seems to pick the layout to use: > > > > 133: def render(*args,&blk) > > 134: opts = (Hash === args.last) ? args.pop : {} > > 135: > > 136: action = opts[:action] || params[:action] > > 137: opts[:layout] ||= _layout > > > > And since I didn''t pass anything for args, it should use the _layout > > I''ve set, right? Yet it doesn''t. > > > > So, anyone know how I can specify a controller''s layout? > > _______________________________________________ > > Merb-devel mailing list > > Merb-devel at rubyforge.org > > http://rubyforge.org/mailman/listinfo/merb-devel > > > _______________________________________________ > Merb-devel mailing list > Merb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/merb-devel >Perfect! I defined this in my Application controller: class Application < Merb::Controller def self.layout(name) self._layout = name.to_s end end So now, in any controllers I can do: class Admin::Users < Application layout :admin end I''d like to see something like that added to Merb, so I''ll make a ticket and maybe others will agree. Thanks, Yann. http://merb.devjavu.com/ticket/448