2013-05-03 8 views
8

私が考案(2.2.3)を使用し、このjQueryのAJAX呼び出しを使用して、ユーザーのために、「編集」フォームをロードしようとしています:Rails 3.2.13/Devise 2.2.3:メソッド "authenticate_scope!"エラーがスローされます:間違った引数の数(0 1)

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

この意志

:最終的に呼ばれています方法がある

devise/app/controllers/devise/registrations_controller.rb 

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

...宝石ファイルから...

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

...このbefore_filterを呼び出します

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

しかし、私が削除したときに ":力=>真" は、エラーが消える:

# 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"とはどういう意味...私はそれをそのまま残すとエラーになるのですか? このような猿のパッチを作るのは悪い考えです。しかし、エラーを避けるために他に何ができますか?

ありがとうございました!

答えて

19

はそれを考え出した:問題は、私はApplicationControllerにで...方法...

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

    # then hand over to Devise's method 
    super 
end 

をオーバーライドしていたでした。私は私が今言っていると思い

+1

誰かを助け

def authenticate_user!(options={}) # do some stuff # of my own here # then hand over to Devise's method super(options) end 

希望、いつの日か、多分...:しかし、それはこのように見なければならないおかげで、@TomDoggを、あなたは本当にスマート:-)です – TomDogg

+0

何かを理解していない2時間後(しかし、掘り下げて掘り下げる)、感謝!私たちはまったく同じ問題を抱えていました。コメントに答えて、あなたは質問からすべてのuppointsに値する! :) –

+0

ちょうど同じ問題があった、ありがとう! – ABrowne

関連する問題