Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise 2.0 'layout_by_resource' deprecation warnings when running specs

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?

like image 935
mshafrir Avatar asked Jan 24 '12 19:01

mshafrir


2 Answers

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.

like image 197
ErwinM Avatar answered Nov 18 '22 22:11

ErwinM


Since Rails 3.2 the layout will be looked up automatically. When you use a view in the 'devise' folder, Rails is smart enough to search for the 'devise' layout in the layouts folder. Removing this code would solve the depreciation warnings.

However, this would mean that the admin and agent resource will both use the devise layout. I don't know how to fix this whiteout getting the same depreciation warning.

like image 43
Sweam Avatar answered Nov 18 '22 21:11

Sweam