我使用 Devise (2.2.3) 并尝试使用此 jQuery ajax 调用为用户加载“编辑”表单:
$.ajax({
type: 'GET',
url: '/users/edit',
data: {
id: id
}
});
这将调用此 before_filter...
prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
...来自宝石文件...
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”是什么意思......为什么当我把它留在原地时会出现错误?我想像这样对 gem 代码进行猴子补丁是个坏主意。但是我还能做些什么来避免错误呢?
谢谢你的帮助!