8
我使用的设计(2.2.3),我试图加载“编辑”的形式使用此jQuery的Ajax调用用户:Rails 3.2.13/Devise 2.2.3:方法“authenticate_scope!”抛出错误:错误的参数数目(1 0)
$.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
```
但是当我删除 “:力=> 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”意味着......当我离开它时为什么会出现错误? 我想这是一个坏主意,像这样猴子补丁宝石代码。但我还能做些什么来避免错误?
感谢您的帮助!
我想我不得不说现在:谢谢,@TomDogg,你真聪明:-) – TomDogg 2013-05-03 17:55:54
两个小时后没有了解任何东西(但深入研究设计),谢谢!我们有完全相同的问题。你值得所有的问题,通过回答评论! :) – 2013-08-20 10:29:17
刚刚有同样的问题,谢谢! – ABrowne 2014-02-12 21:19:47