Marius Pop
Marius Pop

Reputation: 1461

Why is flash being persistent on new request?

I have the following code in my controller:

  def show
    @activity = current_user.activities.find(params[:id])
    if graph.good_data?(params)
      graph.time_frame(params)
    else
      flash[:error] = "Please enter valid data."
      graph.default
    end
  end

When I enter invalid data flash[:error] receives a message and everything is displayed accordingly. If I enter valid data after I entered invalid data the action performs as it is supposed. graph.time_frame(params) does it's job. However the flash[:error] message persists with this next request. If I enter valid data again the flash[:error] message disappears. Does anybody know why this is happening?

Upvotes: 0

Views: 118

Answers (1)

alex
alex

Reputation: 3742

Use flash.now[:error], it's specialy for this situation.

Upvotes: 2

Related Questions