HTML 闪现后显示在页面上

HTML shows on page after flash

当用户输入他们的电子邮件时,我有一个成功的闪光通知,当出现问题时,我有一个失败的闪光通知。两者都起作用,但通知下有一个小数字。当我推送到 heroku 时,flash 下显示的整行 html 代码不只是一个数字 -- <div class='background'> <div class='alert alert-success'>Thanks for staying up to date.</div>

haml 视图:

%body
= if flash[:notice]
  .alert.alert-success= flash[:notice]
= if flash[:alert]
  .alert.alert-danger= flash[:alert]

控制器:

respond_to do |format|
  if @lead.save
    format.html { redirect_to :back, :notice => 'Thanks for staying up to date.' }
  else
    format.html { redirect_to :back, :alert => 'Uh oh, there was a problem.'}
  end
end

The output

提前致谢~!

您需要将 = 替换为 -

当您需要在 html 视图中显示/呈现输出时使用 =

当你只需要评估某些东西或分配类似的东西时使用 -

%body
- if flash[:notice]
  .alert.alert-success= flash[:notice]
- if flash[:alert]
  .alert.alert-danger= flash[:alert]