问题描述
我使用的是Rails 3.2.0和Devise 2.0.0.rc2。当我运行我的规范时,我得到一个不赞成的警告,我没有看到我什么时候通常启动我的Rails服务器。 $ rake
.DEPRECATION警告:在devise中找到的
的版面DeviseController,但父控制器设置布局为:layout_by_resource。
请明确地将您的布局设置为devise或
将其设置为nil以强制进行动态查找。
(从实时调用
/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_by_resource
保护
def layout_by_resource
如果devise_controller?
如果resource_name ==:agent&&& action_name =='new'
nil
elsif resource_name ==:admin&&& action_name =='new'
nil
else
'devise'
end
else
'application'
end
end
end
任何想法我为什么看到这些警告? p>
如果要摆脱消息,最简单的解决方案实际上是将您的设计布局模板重命名为 devise.html.erb
,fe到 devise_layout.html.erb
。当然,您可以调整 layout_by_resource
函数来匹配新名称。
这将阻止您的测试中的弃用邮件并使它们再次可读。
I'm using Rails 3.2.0 and Devise 2.0.0.rc2. When I run my specs, I get a deprecation warning that I don't see when I normally start my Rails server.
$ 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)
My /app/controllers/application_controller.rb
looks like:
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
Any idea why I'm seeing these warnings?
If you want to get rid of the messages, the easiest solution is actually to rename your devise layout template to something other than devise.html.erb
, f.e. to devise_layout.html.erb
. Of course you adjust your layout_by_resource
function to match the new name.
This will stop the deprecation messages in your tests and make them readable again.
这篇关于Devise 2.0'layout_by_resource'运行规范时的弃用警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!