devise icon indicating copy to clipboard operation
devise copied to clipboard

block in with_devise_exclusive_scope': undefined method `[]=' for #<ActionDispatch::Routing::Mapper::Scope:0x007f8b29ea4938> (NoMethodError)

Open aantix opened this issue 11 years ago • 5 comments

master broken with commit https://github.com/rails/rails/commit/5e81e6ca31aa0d2a38f8db5c8fe9bcbce98d9689 from @tenderlove.

Devise relies upon that setter for setting scope route attributes https://github.com/plataformatec/devise/blob/master/lib/devise/rails/routes.rb#L446

/Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/devise-48d82853449b/lib/devise/rails/routes.rb:446:in `block in with_devise_exclusive_scope': undefined method `[]=' for #<ActionDispatch::Routing::Mapper::Scope:0x007f8b29ea4938> (NoMethodError)
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/devise-48d82853449b/lib/devise/rails/routes.rb:446:in `each_pair'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/devise-48d82853449b/lib/devise/rails/routes.rb:446:in `with_devise_exclusive_scope'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/devise-48d82853449b/lib/devise/rails/routes.rb:248:in `block (2 levels) in devise_for'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/devise-48d82853449b/lib/devise/rails/routes.rb:351:in `block in devise_scope'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/actionpack/lib/action_dispatch/routing/mapper.rb:939:in `block in constraints'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/actionpack/lib/action_dispatch/routing/mapper.rb:815:in `scope'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/actionpack/lib/action_dispatch/routing/mapper.rb:939:in `constraints'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/devise-48d82853449b/lib/devise/rails/routes.rb:350:in `devise_scope'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/devise-48d82853449b/lib/devise/rails/routes.rb:247:in `block in devise_for'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/devise-48d82853449b/lib/devise/rails/routes.rb:223:in `each'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/devise-48d82853449b/lib/devise/rails/routes.rb:223:in `devise_for'
    from /Users/aantix/dev/followup/config/routes.rb:9:in `block in <top (required)>'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/actionpack/lib/action_dispatch/routing/route_set.rb:402:in `instance_exec'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/actionpack/lib/action_dispatch/routing/route_set.rb:402:in `eval_block'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/actionpack/lib/action_dispatch/routing/route_set.rb:380:in `draw'
    from /Users/aantix/dev/followup/config/routes.rb:3:in `<top (required)>'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/activesupport/lib/active_support/dependencies.rb:296:in `load'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/activesupport/lib/active_support/dependencies.rb:296:in `block in load'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/activesupport/lib/active_support/dependencies.rb:268:in `load_dependency'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/activesupport/lib/active_support/dependencies.rb:296:in `load'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/railties/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/railties/lib/rails/application/routes_reloader.rb:40:in `each'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/railties/lib/rails/application/routes_reloader.rb:40:in `load_paths'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/railties/lib/rails/application/routes_reloader.rb:16:in `reload!'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/railties/lib/rails/application/routes_reloader.rb:26:in `block in updater'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/activesupport/lib/active_support/file_update_checker.rb:75:in `call'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/activesupport/lib/active_support/file_update_checker.rb:75:in `execute'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/railties/lib/rails/application/routes_reloader.rb:27:in `updater'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/railties/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/railties/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/railties/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/railties/lib/rails/initializable.rb:30:in `run'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/railties/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/aantix/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
    from /Users/aantix/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
    from /Users/aantix/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
    from /Users/aantix/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
    from /Users/aantix/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:345:in `each'
    from /Users/aantix/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:345:in `call'
    from /Users/aantix/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
    from /Users/aantix/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
    from /Users/aantix/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/railties/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/railties/lib/rails/application.rb:352:in `initialize!'
    from /Users/aantix/dev/followup/config/environment.rb:5:in `<top (required)>'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/activesupport/lib/active_support/dependencies.rb:302:in `require'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/activesupport/lib/active_support/dependencies.rb:302:in `block in require'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/activesupport/lib/active_support/dependencies.rb:268:in `load_dependency'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/activesupport/lib/active_support/dependencies.rb:302:in `require'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/railties/lib/rails/application.rb:328:in `require_environment!'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/railties/lib/rails/commands/commands_tasks.rb:147:in `require_application_and_environment!'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/railties/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/railties/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /Users/aantix/.rvm/gems/ruby-2.2.2/bundler/gems/rails-5e81e6ca31aa/railties/lib/rails/commands.rb:18:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

aantix avatar Aug 09 '15 18:08 aantix

Having this issue.

alejandrodevs avatar Aug 12 '15 16:08 alejandrodevs

Having this issue.

chasik avatar Aug 13 '15 11:08 chasik

Same. Great explanation.

alanwilhelm avatar Aug 13 '15 19:08 alanwilhelm

I'm having a hard time getting the Devise tests to run, but I think this (untested) patch should fix it:

diff --git a/lib/devise/rails/routes.rb b/lib/devise/rails/routes.rb
index 817c736..ead0a4a 100644
--- a/lib/devise/rails/routes.rb
+++ b/lib/devise/rails/routes.rb
@@ -415,7 +415,6 @@ options to another `devise_for` call outside the scope. Here is an example:
 ERROR
         end

-        path, @scope[:path] = @scope[:path], nil
         path_prefix = Devise.omniauth_path_prefix || "/#{mapping.fullpath}/auth".squeeze("/")

         set_omniauth_path_prefix!(path_prefix)
@@ -426,27 +425,25 @@ ERROR
           constraints: { provider: providers },
           to: "#{controllers[:omniauth_callbacks]}#passthru",
           as: :omniauth_authorize,
+          path: nil,
           via: [:get, :post]

         match "#{path_prefix}/:action/callback",
           constraints: { action: providers },
           to: "#{controllers[:omniauth_callbacks]}#:action",
           as: :omniauth_callback,
+          path: nil,
           via: [:get, :post]
-      ensure
-        @scope[:path] = path
       end

       def with_devise_exclusive_scope(new_path, new_as, options) #:nodoc:
-        current_scope = @scope.dup
-
         exclusive = { as: new_as, path: new_path, module: nil }
         exclusive.merge!(options.slice(:constraints, :defaults, :options))

-        exclusive.each_pair { |key, value| @scope[key] = value }
+        @scope = @scope.new exclusive
         yield
       ensure
-        @scope = current_scope
+        @scope = @scope.parent
       end

       def constraints_for(method_to_apply, scope=nil, block=nil)

tenderlove avatar Aug 13 '15 20:08 tenderlove

@tenderlove that patch fails locally with 4.2.2 and we have a ton of other failures when pointing the test suite to Rails master that we need to take care of it first.

lucasmazza avatar Aug 14 '15 03:08 lucasmazza