title: How can I pass validation error messages to a method in a different controller?
body: <p>I am just starting a rails 3 app that has a parent model and a child model (parent has_many :children).</p>
  
  <p>I am trying to set things up so that after creating a new parent the user is taken to the show action of that parent (/parent/id). In this view I have included partials to show any children and a form to create a new child. After creating a new child the user is redirected to the show action for the parent where the new child will appear. This all works as intended.</p>
  
  <p>However, if I try to validate fields in the new child form any error messages that occur are not appearing in the form (the necessary lines in the view are there and are correct - cut and pasted from generated scaffold code). Is there a way of passing these error messages for the child successfully to the parent show action?</p>
  
  <p>Here are snippets of relevant code;</p>
  
  <p>From my parent controller:</p>
  
  <pre><code>def show
    @parent = Parent.find(params[:id])
    @child = @parent.children.new
  
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml =&gt; @admission }
    end
  end
  </code></pre>
  
  <p>From my child controller:</p>
  
  <pre><code>def create
    @child = Child.new(params[:parent])
  
    respond_to do |format|
      if @child.save
        format.html { redirect_to(parent_path(params[:child][:parent_id]), :notice =&gt; 'Child was successfully created.') }
                 #This works as intended
        format.xml  { render :xml =&gt; @child, :status =&gt; :created, :location =&gt; @child }
      else
        format.html { redirect_to parent_path(params[:child][:patient_id]) }
                 #This redirects where I want it to go when validation fails but error messages are lost
        format.xml  { render :xml =&gt; @child.errors, :status =&gt; :unprocessable_entity }
      end
    end
  end
  </code></pre>