1
votes

how can I update my user without the required password, password confirmation and current password?

I'm trying to update the user outside devise controller, my form is working with this helper:

module ContentHelper
  def resource_name
    :user
  end

  def resource
    @resource ||= User.new
  end

  def devise_mapping
    @devise_mapping ||= Devise.mappings[:user]
  end
end

and my form for editing:

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put, multipart: true }) do |f| %>
<%= devise_error_messages! %>


    <%= f.file_field :personal_file, placeholder: "Upload file" %>

    <%= f.submit %>

     <%   end %>

With this its appearing that I can't have my password blank and redirecting to user edit page:

Password is too short (minimum is 8 characters)
Password can't be blank
Current password can't be blank
1

1 Answers

0
votes

You can just write up your own controller that updates User as you wish. Something like

class UserController < ApplicationController
  before_filter :authenticate_user!
  def update
    current_user.update(user_params)
  end

  private

  def user_params
    params.require(:user).permit(:personal_file)
  end
end

would do the trick. You don't need to think of the current_user as some magic devise thing but instead use it as any other model you have.

If you anyway wish to use Devise controller to do this, you should see this answer.