Allow params to be nil by using fetch method instead of require.
private
def food_record_params
params.fetch(:food_record, {}).permit(:image)
end
Implemented image upload function using carrierwave.
gem 'carrierwave'
How to use carrierwave https://qiita.com/uchida0331/items/f99aba46fd1a6df9e753
On the image upload screen, if you press the registration button while the image is not selected, an event that transitions to the error screen occurs.
As shown in the error log, if the parameter does not contain a value in the require method, an error will occur. This is because require is a method for throwing an exception when params does not contain a value.
ruby2.7 reference https://docs.ruby-lang.org/ja/latest/method/Hash/i/fetch.html