I just want to flash an notice/error if the message is/isn't saved, without any redirect, how can I have no redirect:
respond_to do |format|
if @message.save
format.html { redirect_to request.referer, :notice => 'Message sent!' } #dont want redirect
else
# error message here
end
Use flash.now
:
if @message.save
flash.now[:notice] = 'Message sent!'
else
flash.now[:alert] = 'Error while sending message!'
end
respond_to do |format|
format.html { # blahblah render }
end
In rails 5, you can do:
format.html { redirect_to request.referer, alert: 'Message sent!' }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With