'Ruby on Rails Flash[:notice] not working after deploying to Heroku

I have an app that has had working flashes while hosted locally, but after deploying to heroku they no longer work.

Here is my controller:

def create
@query = Query.new(params[:query])

respond_to do |format|
  if @query.save
    QueryMailer.new_query_email(@query).deliver
    format.html { redirect_to @query, notice: 'Query was successfully created.' }
    format.json { render json: @query, status: :created, location: @query }
  else
    format.html { render action: "new" }
    format.json { render json: @query.errors, status: :unprocessable_entity }
  end
end
end

And the view:

<% if flash[:notice] %>
<div class="notice"><%= flash[:notice] %></div>
<% end %>


Solution 1:[1]

Please use this:

flash.now[:notice]

and also check the notice class is correct in html.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dheer