Rails 3.2.13 / Devise 2.2.3: Метод "authenticate_scope!" выдает ошибку: неверное количество аргументов (1 для 0)

Я использую Devise (2.2.3) и пытаюсь загрузить форму "edit" для пользователя, используя этот jjuery-вызов ajax:

$.ajax({
  type: 'GET',
  url: '/users/edit',
  data: {
    id: id
  }
});

Это будет называть это before_filter...

prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]

... из файла gem...

devise/app/controllers/devise/registrations_controller.rb

(see: https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb)

Метод, который в конечном итоге называется:

# 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

И ошибка, которую я получаю:

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
```

Но когда я удаляю ":force => true", ошибка исчезает:

# 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

Поэтому мне интересно, что означает ": force => true"... Почему я получаю ошибку, когда оставляю ее на месте? Я полагаю, это плохая идея, чтобы обезьяна-патч гем-код, как это. Но что еще я могу сделать, чтобы избежать ошибки?

Спасибо за вашу помощь!

1 ответ

Решение

Разобрался: проблема была в том, что я переопределил метод...

def authenticate_user!
  # do some stuff
  # of my own here

  # then hand over to Devise's method
  super
end

... в контроллере приложений. Но это должно выглядеть так:

def authenticate_user!(options={})
  # do some stuff
  # of my own here

  # then hand over to Devise's method
  super(options)
end

Надеюсь, это поможет кому-нибудь, может быть, когда-нибудь...

Другие вопросы по тегам