Bijendra
Bijendra

Reputation: 10025

Flash[:notice] remains after form submission

When the form gets submitted the flash message is displayed and the user remains at the same page with all fields filled.Now if one of the required fields id deleted and again we submit the form, the error is not displayed and the flash[:notice] is displayed.When i refresh the page the notice goes off.unable to figure out the reason .i have given the view code and in controller

flash[:notice] = "Saved Successfully"

View code:

   <b><h3><%= flash[:notice] %></h3></b>
<% semantic_form_for(@featured_business, {:url => "#{@signin_link}".gsub(/\/+/, '/'), :html => {:multipart => true, :class => 'validate business'}}) do |f| %>
<% f.inputs do %>

  <%= hidden_field_tag 'more_validations_required' %>
  <%= f.input :name, :label => ' Name:' , :input_html => { :style => "width:240px;" }%>
  <%= f.input :contact_name, :label => 'Contact name:',:required => false, :input_html => { :style => "width:240px;" } %>
  <%= f.input :phone, :label => 'Phone Number:', :input_html => { :style => "width:240px;" }  %>
  <%= f.input :email, :label => 'Email:', :input_html => { :class => 'email' } , :input_html => { :style => "width:240px;" } %>


  <%= f.commit_button :label => "", :button_html => {:class => 'signup business'} %>
<% end %>

<% end %>

Upvotes: 1

Views: 537

Answers (1)

Gazler
Gazler

Reputation: 84150

Flash messages exist for the next page only. If you refresh the page then the flash message is no longer stored in the session.

Here is a good blog post to help you understand flash messages. http://travisonrails.com/2008/08/17/working-with-the-flash-hash

Upvotes: 1

Related Questions