Skip to content

Instantly share code, notes, and snippets.

Created August 25, 2014 14:06
Show Gist options
  • Save anonymous/1ff2dc6666eb4894bcf7 to your computer and use it in GitHub Desktop.
Save anonymous/1ff2dc6666eb4894bcf7 to your computer and use it in GitHub Desktop.
Devise edit user without password when sign in though facebook
class Users::RegistrationsController < Devise::RegistrationsController
before_action :configure_permitted_parameters
# Handles editing when provider is facebook
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
<...>
<% if resource.provider != "facebook" %>
<div class="form-group">
<%= f.label :current_password, class: "col-lg-2 control-label" %>
<i>(we need your current password to confirm your changes)</i>
<div class="col-lg-10">
<%= f.password_field :current_password, autocomplete: "off", class: 'form-control' %>
</div>
</div>
<div class="form-group">
<%= f.label :password, class: "col-lg-2 control-label" %>
<i>(leave blank if you don't want to change it)</i>
<div class="col-lg-10">
<%= f.password_field :password, autocomplete: "off", class: 'form-control' %>
</div>
</div>
<div class="form-group">
<%= f.label :password_confirmation, class: "col-lg-2 control-label" %>
<div class="col-lg-10">
<%= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control' %>
</div>
</div>
<% end %>
<...>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment