Ruby on Rails - render layout
The method render
will actually attempt to render content; you should not call it when all you want to do is set the layout.
Rails has a pattern for all of this baked in. Simply pass a symbol to layout
and the method with that name will be called in order to determine the current layout:
class MyController < ApplicationController layout :admin_layout private def admin_layout # Check if logged in, because current_user could be nil. if logged_in? and current_user.is_able_to('siteadmin') "admin" else "application" end endend
perhaps you need to check that the user is signed in first?
def admin_layout if current_user and current_user.is_able_to 'siteadmin' render :layout => 'admin' else render :layout => 'application' endend
It might be because current_user
is nil
when the user is not logged in. Either test for .nil?
or initialize the object.