Forum: Ruby on Rails Action Specific Layouts

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.
E25296bf52723dc37bc462271eb02d2d?d=identicon&s=25 Jason Pfeifer (jpfeifer)
on 2008-11-12 01:18
Greetings,

I'm wondering if I can do action specific layouts in an elegant way like
this:

class AuthorsController < ApplicationController
  before_filter :is_admin?, :only => [:new, :create, :edit, :update,
:destroy]

  layout "admin", :except => [:index, :show]

  make_resourceful do
    actions :index, :show, :new, :create, :edit, :update
  end

end

I'm aware that you can do it in each action with:

def index
  render :layout => "layout"
end

However, in a need to keep it clean I don't want to write that.  Looking
at the layout method source, it appears that it should accept options.
However, if I set :only or :except the layout is only correctly "admin"
for the ones specified (or excepted), and the others render without a
layout.

Thoughts?

Thanks,

Jason
D69d23d8e811e8ab2a8593380d6ede63?d=identicon&s=25 Jeff Emminger (jemminger)
on 2008-11-12 14:51
(Received via mailing list)
perhaps a before or after filter to set it based on
controller.action_name ?


On Nov 11, 7:18 pm, Jason Pfeifer <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.