Ruby on rails 闪存消息在重新加载时仍然存在

Ruby on rails 闪存消息在重新加载时仍然存在,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我有如下简单的动作: def edit_password end def update_password if @user.update(user_params) redirect_to @user, notice: "Password was successfully changed" else flash.now[:notice] = "Password not changed" render :edit_password end end 我认为: &

我有如下简单的动作:

def edit_password
end

def update_password
  if @user.update(user_params)
    redirect_to @user, notice: "Password was successfully changed"
  else
    flash.now[:notice] = "Password not changed"
    render :edit_password
  end
end
我认为:

<% if flash[:error] 
  <%=flash[:error] %>
<% end %>

我也遇到了同样的问题,下面是我为解决这个问题所做的。我在action_controller中创建了以下方法,并在需要时从其他控制器中将其作为before_action筛选器调用:

def clear_flash_messages
  flash[:notice] = nil
  flash['danger'] = nil
  flash['success'] = nil
  flash[:warning] = nil
end

这将有效地清除所有过时的闪存消息,并允许您启动新的闪存,无论您是简单地重新加载还是重定向。

闪存将在整个会话中持续,直到执行新操作。谢谢。我不知道,不客气,雷姆