[RUBY] [Rails] How to delete images uploaded by carrierwave (using devise)

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.

Added column to devise strong parameter

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.


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])

This eliminates the error and allows you to safely delete the image!

Recommended Posts

[Rails] How to delete images uploaded by carrierwave (using devise)
[Rails] How to upload images using Carrierwave
[Rails] How to upload multiple images using Carrierwave
[rails] How to post images
[Rails] How to install devise
How to download images from AWS S3 (rails, carrierwave)
[Rails] How to use gem "devise"
[Rails] How to use devise (Note)
[Rails] How to upload images to AWS S3 using refile and refile-s3
[Rails 5] How to display the password change screen when using devise
[rails6.0.0] How to save images using Active Storage in wizard format
[Note] How to use Rails 6 Devise + cancancan
How to implement image posting using rails
[Rails] How to translate devise into Japanese
[Rails] How to handle data using enum
How to implement a slideshow using slick in Rails (one by one & multiple by one)
[Rails] How to log in with a name by adding a devise name column
[Rails] How to decide the destination by "rails routes"
[Rails] How to create a graph using lazy_high_charts
How to delete a controller etc. using a command
How to output CSV created by Rails to S3
How to separate .scss by controller in Rails
How to link images using FactoryBot Active Storage
Rails "How to delete NO FILE migration files"
How to post images on Heroku + CarrierWave + S3
How to write Rails
How to uninstall Rails
[Rails] How to search by multiple values ​​with LIKE
[rails] How to use devise helper method before_action: authenticate_user!
How to delete a new_record object built with Rails
How to delete custom Adapter elements using a custom model
How to delete untagged images in bulk with Docker
[Rails] How to edit and customize devise view and controller
[Rails 6] Add images to seed files (using Active Storage)
Rails learning How to implement search function using ActiveModel
[Rails] How to install a decorator using gem draper
How to implement a circular profile image in Rails using CarrierWave and R Magick
How to delete BOM (UTF-8)
How to test including images when using ActiveStorage and Faker
How to set environment variables when using Payjp with Rails
[Rails] Register by attribute of the same model using Devise
[Rails] How to use enum
How to minimize Java images
[Rails] How to use enum
How to read rails routes
How to input multiple images at once using rake task
Prevent operations! How to securely update Rails manually using transactions
How to use rails join
How to set and describe environment variables using Rails zsh
How to deploy jQuery in your Rails app using Webpacker
[Rails] Add column to devise
[Rails] How to display the list of posts by category
How to terminate rails server
How to write Rails validation
How to write Rails seed
[Rails] How to use validation
Super easy in 2 steps! How to install devise! !! (rails 5 version)
[Rails] How to disable turbolinks
[Rails] How to use authenticate_user!
[Rails] How to use "kaminari"
[Rails] How to implement scraping