I use Devise (2.2.3) and am trying to load the "edit" form for a user using this jQuery ajax call:
$.ajax({
type: 'GET',
url: '/users/edit',
data: {
id: id
}
});
This will call this before_filter...
prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
...from the gem file...
devise/app/controllers/devise/registrations_controller.rb
(see: https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb)
The method that's eventually called is:
# Authenticates the current scope and gets the current resource from the session.
def authenticate_scope!
send(:"authenticate_#{resource_name}!"), :force => true)
self.resource = send(:"current_#{resource_name}")
end
And the error I get is:
ArgumentError at /users/edit
============================
> wrong number of arguments (1 for 0)
(gem) devise-2.2.3/app/controllers/devise/registrations_controller.rb, line 116
-------------------------------------------------------------------------------
``` ruby
111 signed_in_root_path(resource)
112 end
113
114 # Authenticates the current scope and gets the current resource from the session.
115 def authenticate_scope!
> 116 send(:"authenticate_#{resource_name}!", :force => true)
117 self.resource = send(:"current_#{resource_name}")
118 end
119 end
```
But when I delete the ":force => true", then the error vanishes:
# Authenticates the current scope and gets the current resource from the session.
def authenticate_scope!
send(:"authenticate_#{resource_name}!")) # deleted: :force => true
self.resource = send(:"current_#{resource_name}")
end
So I'm wondering what the ":force => true" means... Why do I get the error when I leave it in place? I suppose it's a bad idea to monkey-patch gem code like this. But what else can I do to avoid the error?
Thanks for your help!
Figured it out: the problem was I had overriden the method...
def authenticate_user!
# do some stuff
# of my own here
# then hand over to Devise's method
super
end
...in the ApplicationController. But it must look like this:
def authenticate_user!(options={})
# do some stuff
# of my own here
# then hand over to Devise's method
super(options)
end
Hope that helps somebody, some day, maybe...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With