I wanted to delete the user image uploaded by carrierwave, and when I saw the official github,
<%= f.check_box :remove_avatar %>
Remove avatar
It was written that it can be deleted by installing such a check box, so I tried it. Easy! Then the following error occurs.
Unpermitted parameter: :remove_image
Not allowed means that you need to add a column called: remove_image to the strong parameter when removing.
This time I use devise around the user, and upload and delete images when editing the user. So I had to add: remove_image to the key of devise_parameter_sanitizer.permit (: account_update,) to allow it.
controllers/application_controller.rb
class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:account_update, keys: [:name, :profile, :image, :remove_image])
end
end
This eliminates the error and allows you to safely delete the image!
Recommended Posts