In my controller I have the following code:
format.html { redirect_to new_customer_url,
notice: %Q
Here is one possible way to solve this problem. Add a before filter to your ApplicationController
which will make flash[:notice]
html safe only if flash[:html_safe]
is set. Then you can control when and when not to make notices html safe completely from the controller.
before_filter -> { flash.now[:notice] = flash[:notice].html_safe if flash[:html_safe] && flash[:notice] }
Then your example could be modified to this:
format.html do
redirect_to(
new_customer_url,
notice: %Q[ A customer already exists with with this shopping id. Edit this customer #{view_context.link_to("here", edit_customer_url(@duplicate))}.],
flash: { html_safe: true }
)
end