Popup message persists across reboots

I have simple steps that look like this:

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

      

In my opinion, I have:

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

      

The flash message is displayed correctly (when the password has not been changed). But when I reload the page, the message persists. I believe it should disappear on the update page. What am I doing wrong? I've looked all over the place and it seems so simple, but I can't figure it out. Appreciate any help.

+3


source to share


1 answer


I had the same problem and here's what I did to get around it. I created the following method in action_controller and call it as a before_action filter from my other controllers where needed:

def clear_flash_messages flash [: notification] = zero flashing ['danger'] = zero flashing ['success'] = zero flashing [: warning] = zero ends



This will effectively remove all obsolete Flash messages and allow you to start a new one, whether you are reloading or simply redirecting.

0


source







All Articles