title: Rails 3 - Create a button/link to send emails
body: <p>In my app I have a method that collect all the <code>Projects</code> I have in an Array and using <code>each</code> I show a link to the user that is accessing, a link to this project.</p>
  
  <p>Well, what I want to do is create a button or a link besides this link to the project that enables me to send an email to the project owner. Working on this for a while and with some help here I discovered that I need to create a method in my <code>Projects</code> controller to call the method in my Mailer.</p>
  
  <p>But I think that the way things are going probably won't work, so what would be the right and best way to do this: a link or a button to email the project besides it?</p>
  
  <p>Here is what I have done so far:</p>
  
  <p>I created a method inside my <code>Projects</code> controller: </p>
  
  <pre><code>def send_email(email, name)
      ProfileMailer.member_alert(email, name).deliver
      #redirect_to :root
  end
  </code></pre>
  
  <p>And on my view:</p>
  
  <pre><code>&lt;td&gt;&lt;%= link_to "Send Email", send_email_projects_path(project.user.email, project.user.name) %&gt;&lt;/td&gt;
  </code></pre>
  
  <p>Also added a route:</p>
  
  <pre><code>resources :projects do
    collection do
      post "send_email"
    end
  end
  </code></pre>
  
  <p>And on my <code>ProfileMailer</code></p>
  
  <pre><code>  def member_alert(email, name)
      @email = email
      @name = name
      mail(:to =&gt; @email, :subject =&gt; "#{@name}")
    end
  </code></pre>
  
  <p>With that I will probably have to create a new view page for each email commands I want to insert, and I will have probably more to come so that's why I think this isn't the best way.</p>