title: How do I join two models together for reference in an email using Actionmailer
body: <p>I'm trying to create an email which is sent when a Parent (equivalent to a User) creates a new Baby. I've been trying lots of things but can't quite figure out what I'm doing wrong.</p>
  
  <p>Parents have many babies. Babies belong to parents. </p>
  
  <p>I'm sending the email to parents by adding</p>
  
  <pre><code>NewBabyMailer.new_baby_email(@parent).deliver
  </code></pre>
  
  <p>to this block of code in the babies_controller.rb</p>
  
  <pre><code>  def create
      @baby = Baby.new(params[:baby])
      @parent = current_parent
      if @baby.save
        # @baby = Baby.find(params[:id])
        NewBabyMailer.new_baby_email(@parent).deliver
        redirect_to(root_url(:host =&gt; with_subdomain(@baby.subdomain)), :notice =&gt; 'Your baby was successfully added. Share this page with people and tell them to sign up to be notified when your baby is born') 
      else
        render :action =&gt; "new" 
      end
    end
  </code></pre>
  
  <p>In my new newbabymailer.rb mailer I have</p>
  
  <pre><code>    class NewBabyMailer &lt; ActionMailer::Base
        default :from =&gt; "blah"
        default :bcc =&gt; "blah"
        @parent = parent
        @baby = Baby.find_by_parent_id
  
        # @baby = Baby.where(:parent_id = :params[:id])
        def new_baby_email(parent)
          mail(:to =&gt; parent.email, :subject =&gt; "Thanks for adding a baby", :bcc =&gt; "blah")
        end
      end
  </code></pre>
  
  <p>But when I call things like </p>
  
  <pre><code>&lt;%= @baby.name.titleize %&gt;
  </code></pre>
  
  <p>in my newbabyemail.html.erb, I get </p>
  
  <pre><code>undefined method `baby' for nil:NilClass
  </code></pre>
  
  <p>Any suggestions as to what I am doing wrong? I'm sure it's something really simple, but it's stumped me for the whole day. </p>
  
  <p>Cheers
  Paul</p>