2017-08-31 3 views
0

ユーザアカウントを変更するたびにパスワードを変更せずにdeviseのユーザアカウントを更新できるようにしようとしています。これを行うには、update_resourceメソッドを変更する必要がありますが、私はDoubleRenderErrrorを取得しており、これを修正する方法がわかりません。それはスタンドとしてここActiveAdmin内でdeviseのために `update_resource`を実行するときにDoubleRenderErrorを取得する

は私のコードです:

controller do 
    protected 
    def update_resource(resource, params) 
     if params.first[:password].blank? 
     resource.update_without_password(params.first) 
     else 
     resource.update_attributes(params.first) 
     end 
     if resource.errors.blank? 
     redirect_to admin_users_path, :notice => "User updated successfully." 
     else 
     render :edit 
     end 
    end 
    end 

答えて

1

return redirect_to admin_users_path, :notice => "User updated successfully."で既存のコードredirect_to admin_users_path, :notice => "User updated successfully."を交換してください。これが助けてくれるといいなあそうでないとき

+0

サイコロはありません:(しかし、ありがとうございます。 – Thermatix

+0

こちらも同様の問題の解決策が見つかります。 [link_here](https://stackoverflow.com/questions/21610090/double-render-error-rails) –

+0

私はあなたが解決策を見つけてうれしいです:) –

0

私のミスは私がオーバーライドされたメソッドupdate_resourceを考えていたがupdateメソッドのオーバーライドそのものだった、その結果として、それが2回リダイレクト/レンダリングのでupdate方法を実行している、私のオーバーライドを実行していました。

すべてのレンダリング/リダイレクトを削除すると問題が解決しました。

私は、GitHubの上this issueを見た後、特にこのコードスニペット私のミスを実現:

def update_resource(object, attributes) 
    puts "==================before update=====================" 
    debugger 
    object.update_attributes(*attributes) 
    puts "=================after update=====================" 
end  
def update(options={}, &block) 
    super do |success, failure| 
    block.call(success, failure) if block 
    failure.html { render :edit } 
    end 
end 

をあなたが見ることができるように、更新方法とupdate_resource方法は別の方法です。

関連する問題