Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

layout with symbol generates error

I have a admin namespace and Admin::UserController controller. When I try to use a layout called admin with symbol, the rails throw an exception, but if I call layout admin as a string, works sucessfull.

The exception message is the following:

You specified nil as the layout, but no such method was found

I just want to know why this happens...

thanks.

like image 303
rizidoro Avatar asked Jan 20 '23 00:01

rizidoro


1 Answers

As per here:

http://ap.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html

Sometimes you want to alternate layouts depending on runtime information, such as whether someone is logged in or not. This can be done either by specifying a method reference as a symbol or using an inline method (as a proc).

So long story short, when you specify a symbol, Rails actually expects that to be a method reference, thus the reason why it is claiming that there was no method found.

like image 111
Mike Lewis Avatar answered Jan 28 '23 09:01

Mike Lewis