运行规范时设计2.0’layout_by_resource’弃用警告

我正在使用Rails 3.2.0和Devise 2.0.0.rc2。 当我运行我的规范时,我收到一个弃用警告,当我正常启动Rails服务器时,我没有看到。

$ rake .DEPRECATION WARNING: Layout found at "devise" for DeviseController but parent controller set layout to :layout_by_resource. Please explicitly set your layout to "devise" or set it to nil to force a dynamic lookup. (called from realtime at /Users/foo/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:310) 

我的/app/controllers/application_controller.rb看起来像:

 class ApplicationController < ActionController::Base protect_from_forgery layout :layout_by_resource protected def layout_by_resource if devise_controller? if resource_name == :agent && action_name == 'new' nil elsif resource_name == :admin && action_name == 'new' nil else 'devise' end else 'application' end end end 

知道我为什么看到这些警告吗?

如果你想摆脱这些消息,最简单的解决方案实际上就是将你的设计布局模板重命名为devise_layout.html.erb以外的其他东西,fe到devise_layout.html.erb 。 当然,您可以调整layout_by_resource函数以匹配新名称。

这将停止测试中的弃用消息并使其再次可读。

从Rails 3.2开始,将自动查找布局。 当您在’devise’文件夹中使用视图时,Rails足够聪明,可以在layouts文件夹中搜索’devise’布局。 删除此代码将解决折旧警告。

但是,这意味着管理员和代理资源都将使用设计布局。 我不知道如何修复此whiteout获得相同的折旧警告。