Use alert(<%= JSON.generate(ERB::Util::html_escape(@notice)) =>), which will work for all text, including with line breaks, prevent XSS, etc.
alert(<%= JSON.generate(ERB::Util::html_escape(@notice)) =>)
https://code.dblock.org/2024/10/30/safely-passing-ruby-variables-to-javascript-in-erb.html