Undefined method failure_app for nil:NilClass

poseid picture poseid · Oct 11, 2012 · Viewed 8.2k times · Source

I am trying to use devise from a Rails app to grant access to a Sinatra application within the Rack middleware.

My config/routes.rb has:

authenticate "admin" do
  mount Admins::Dashboard, :at => "/admins"                                                                                                        
end

In my Sinatra app, I use:

before do
  env["warden"].authenticate!(:scope => "admin")                                                                                                 
end

get "/dashboard" do
  erb :dashboard
end

Now, I get an error with the following stacktrace:

Started GET "/admins/dashboard" for 127.0.0.1 at 2012-10-11 08:45:13 +0200

NoMethodError (undefined method `failure_app' for nil:NilClass):
  devise (2.1.2) lib/devise/delegator.rb:11:in `failure_app'
  devise (2.1.2) lib/devise/delegator.rb:5:in `call'
  warden (1.2.1) lib/warden/manager.rb:130:in `call_failure_app'
  warden (1.2.1) lib/warden/manager.rb:116:in `process_unauthenticated'
  warden (1.2.1) lib/warden/manager.rb:47:in `call'
  actionpack (3.2.8) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  rack (1.4.1) lib/rack/etag.rb:23:in `call'
  rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'

Answer

Prakash Murthy picture Prakash Murthy · Oct 12, 2012

The error message is a complaint about missing configuration for customizing the warden failure app to point to sinatra.

Check out this previous answer and the related (detailed) blogpost about setting up Sinatra+Warden & Rails+Devise; hopefully the instructions there will help you implement the solution successfully.