Editing Users With Devise and Omniauth

前端 未结 3 1863
既然无缘
既然无缘 2020-12-13 16:18

I\'m working through the Railscast on implementing Devise and OmniAuth (along with the Devise documentation) -- currently, I\'ve got a site going where visitors can sign up

3条回答
  •  清歌不尽
    2020-12-13 16:33

    The easiest way is to overwrite the update_resource method in your RegistrationsController. This is advised by devise in their own implementation of the controller:

      # By default we want to require a password checks on update.
      # You can overwrite this method in your own RegistrationsController.
      def update_resource(resource, params)
        resource.update_with_password(params)
      end
    

    So the solution is to overwrite this method in your own controller like this:

    class Users::RegistrationsController < Devise::RegistrationsController
    
      # Overwrite update_resource to let users to update their user without giving their password
      def update_resource(resource, params)
        if current_user.provider == "facebook"
          params.delete("current_password")
          resource.update_without_password(params)
        else
          resource.update_with_password(params)
        end
      end
    
    end
    

提交回复
热议问题