title: Rails: Losing flash/errors from embedded form after redirect_to
body: <p>This is a stupid example but I'm trying to understand how thing get passed around behind the scenes in Rails. And there's probably a better, "Rails", way to approach this...if so please let me know. I have:</p>
  
  <pre><code>Warren has_many Rabbits
  Rabbit belongs_to Warren
  </code></pre>
  
  <p>I'm listing existing rabbits and then providing a form for adding a new rabbit. </p>
  
  <p><strong>warrens/show.html.haml</strong></p>
  
  <pre><code>%h1 This Warren
  
  %h2 Rabbits
  = render @warren.rabbits, :target =&gt; @warren
  
  %h2 Add a rabbit:
  = render "rabbits/form", :parent =&gt; @warren, :foreign_key =&gt; :warren_id
  
  = link_to 'Edit', edit_warren_path(@warren)
  \|
  = link_to 'Back', warrens_path
  </code></pre>
  
  <p>It works. I can add and destroy rabbits while looking at the Warren's show view. The problem is that the <strong>flash</strong> messages (<code>:success</code>, <code>:notice</code>) and/or the <code>rabbit.errors</code> aren't being shown on/in the view. Now, I am <strong>not</strong> using <code>accepts_nested_attributes_for</code> in my warren.rb model. but this is <em>mostly</em> working. Learning Rails so wondering what's going on and <strong>how to get my messages flowing smoothly</strong>...</p>
  
  <p><strong>rabbits/_form.html.haml</strong></p>
  
  <pre><code>= form_for ([parent, parent.rabbits.build]) do |f| 
      = render "shared/error_messages", :target =&gt; parent
  
      .field
          = f.label :name
          = f.text_field :name
      .field
          = f.label :color
          = f.text_field :color
      .field
          = f.hidden_field foreign_key
      .actions
          = f.submit 'Save'
  </code></pre>
  
  <p><strong>layouts/application.html.haml</strong></p>
  
  <pre><code>    !!!
      %html
          %head
                 ...
          %body
              .container
                  - flash.each do |key, value|
                      %div{ :class =&gt; ['flash', key] }= value
                  = yield
  </code></pre>
  
  <p><strong>rabbits_controller.rb</strong></p>
  
  <pre><code>class RabbitsController &lt; ApplicationController
  
    def create
      @warren = Warren.find(params[:warren_id])
      @rabbit = @warren.rabbits.create(params[:rabbit])
      redirect_to @warren
    end
  
    def destroy
      @warren = Warren.find(params[:warren_id])
      @rabbit = @warren.rabbits.find(params[:id])
      @rabbit.destroy
      redirect_to @warren
    end
  </code></pre>
  
  <p><strong>shared/_error_messages.html.haml</strong></p>
  
  <pre><code>-if target.errors.any?
    #error_explanation
      %h2= "#{pluralize(target.errors.count, "error")} prohibited this record from being saved:"
      %ul
        - target.errors.full_messages.each do |msg|
          %li= msg
  </code></pre>