To use flash messages in controller when redirecting you need to use:
flash.alert = "Some errors"
or
flash[:alert] = "Some errors"
if you want render:
flash.now[:notice] = "Some errors"
render :new
But remember, use flash.now when rendering and flash when redirecting
Here you can search the details about this subject:
https://www.rubyguides.com/2019/11/rails-flash-messages/
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…