title: Rails - send email on button click
body: <p>rails 4.1.1</p>
  
  <p>I have an OrdersController and on the orders show action I have...</p>
  
  <p>orders_controller.rb</p>
  
  <pre><code>def show
    @order = Order.find(params[:id])
    @client = Client.find(@order.client_id)
  
    if request.post?
      OrderMailer.order_send(@client, @order).deliver
      flash[:notice] = 'Order details sent!'
      redirect_to order_path(@order.id)
    end
  end
  </code></pre>
  
  <p>Then on the view I have...</p>
  
  <p>(show.haml)</p>
  
  <pre><code>= button_to "Send", @order
  </code></pre>
  
  <p>If I take the "OrderMailer" out of the if statement and visit the show/ order page, the email gets sent repeatedly until I close the dev server so I know the mailer part sends/ works ok.</p>
  
  <p>I am just unsure how to tie the button click/send email together? I need a route but not sure how to tie it together if I already have a route for the orders/show page?</p>
  
  <p>routes.rb</p>
  
  <pre><code>resources :orders, :path =&gt; 'orders'
  </code></pre>