我有一个管理命名空间和 Admin::UserController Controller 。当我尝试使用带有符号的名为 admin 的布局时,rails 抛出异常,但如果我将布局 admin 作为字符串调用,则工作成功。
异常信息如下:
您指定 nil 作为布局,但没有找到这样的方法
我只是想知道为什么会这样......
谢谢。
最佳答案
根据这里:
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).
长话短说,当您指定一个符号时,Rails 实际上期望它是一个方法引用,因此它声称没有找到方法的原因。
关于ruby-on-rails - 带有符号的布局会产生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5671414/