title: How do I use JavaScript to send an email with the Rails 3 Action Mailer?
body: <p>I'm using the Facebook Comments social plugin and I want to be able to send an email every time someone adds a new comment. In the past, I've used Rails' Action Mailer to send emails, but I can't figure out how to get it to work.</p>
  
  <p>I'm listening for the JavaScript event <code>FB.Event.subscribe('comment.create)</code> then I want the callback function to send an AJAX request to the ActionMailer to send out an email. How do I do this?</p>
  
  <p>JavaScript code:</p>
  
  <pre><code>FB.Event.subscribe('comment.create', commentMailer(response))
  
  function commentMailer(response) {
      //code to call function to send mail
  }
  </code></pre>
  
  <p>Rails code:</p>
  
  <pre><code>class UserMailer &lt; ActionMailer::Base
   default :from =&gt; "&lt;email address&gt;"
  
  
    def new_comment_email(user, ride)
      @user = user
      @ride = ride
      emails = ride.users.collect {|user| user.email}
      mail(:to =&gt; emails, :subject =&gt; "etc")
    end
  end
  </code></pre>