title: Extra "Are you sure?" before destroying a record
body: <p>On some of my forms, I have an extra popup confirmation "Are you sure?" before it will actually destroy the record. I'm using Rails 4 and simple_form. Here is an example.</p>
  
  <p>I have a model called Promotions and another called PromotionPurchase.</p>
  
  <p><strong>The models:</strong></p>
  
  <pre><code>class Promotion &lt; ActiveRecord::Base
    has_many :promotion_purchases, dependent: :destroy
  end
  
  class PromotionPurchase &lt; ActiveRecord::Base
    belongs_to :user
    belongs_to :promotion
  end
  </code></pre>
  
  <p><strong>The schema</strong></p>
  
  <pre><code>create_table "promotion_purchases", force: true do |t|
    t.integer  "user_id"
    t.integer  "promotion_id"
    t.string   "status"
    t.string   "stripe_card_token"
    t.string   "phone"
    t.string   "full_name"
    t.datetime "created_at"
    t.datetime "updated_at"
  end
  
  add_index "promotion_purchases", ["promotion_id"], name: "index_promotion_purchases_on_promotion_id"
  add_index "promotion_purchases", ["user_id"], name: "index_promotion_purchases_on_user_id"
  
  create_table "promotions", force: true do |t|
    t.string   "name"
    t.text     "description"
    t.integer  "cost_in_cents"
    t.integer  "amount_available"
    t.string   "category"
    t.datetime "start_date"
    t.datetime "end_date"
    t.datetime "created_at"
    t.datetime "updated_at"
  end
  </code></pre>
  
  <p><strong>And the form:</strong></p>
  
  <pre><code>&lt;div class="content-box"&gt;
  &lt;%= simple_form_for [:admin, @promotion] do |f| %&gt;
    &lt;fieldset id="promotion-form-info"&gt;
      &lt;%= f.input :name %&gt;
      &lt;%= f.input :description %&gt;
      &lt;%= f.input :category %&gt;
      &lt;%= f.input :cost_in_cents, as: :string %&gt;
      &lt;%= f.input :amount_available, as: :string %&gt;
      &lt;%= f.input :start_date, :as =&gt; :date_picker %&gt;
      &lt;%= f.input :end_date, :as =&gt; :datetime_picker %&gt;
      &lt;%= f.button :submit, class: 'btn btn-sm btn-success' %&gt;
    &lt;/fieldset&gt;
  &lt;% end %&gt;
  &lt;% if @promotion.id != nil %&gt;
    &lt;fieldset id="promotion-form-purchases"&gt;
      &lt;h3&gt;Purchases:&lt;/h3&gt;
      &lt;% if !@purchases.empty? %&gt;
        &lt;table class="table"&gt;
          &lt;tr&gt;
            &lt;th&gt;Name&lt;/th&gt;
            &lt;th&gt;Email&lt;/th&gt;
            &lt;th&gt;Phone&lt;/th&gt;
            &lt;th&gt;Status&lt;/th&gt;
            &lt;th&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;% @purchases.each do |purchase| %&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;%= purchase.full_name %&gt;&lt;/td&gt;
              &lt;td&gt;&lt;%= purchase.user.email if purchase.user %&gt;&lt;/td&gt;
              &lt;td&gt;&lt;%= purchase.phone %&gt;&lt;/td&gt;
              &lt;td&gt;&lt;%= purchase.status %&gt;&lt;/td&gt;
              &lt;td&gt;
                &lt;%= link_to "Edit", edit_admin_promotion_promotion_purchase_path(@promotion, purchase), class: "btn btn-xs btn-success" %&gt;
                &lt;%= link_to 'Delete', [:admin, @promotion, purchase], method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-xs btn-danger" %&gt; 
                &lt;%= "&lt;- Editing this purchase" if @purchase &amp;&amp; purchase.id == @purchase.id %&gt;
              &lt;/td&gt;
            &lt;/tr&gt;
          &lt;% end %&gt;
        &lt;/table&gt;
      &lt;% end %&gt;
      &lt;p&gt;
        &lt;%= link_to "Add Purchase", new_admin_promotion_promotion_purchase_path(@promotion), class: "btn btn-sm btn-primary" %&gt;
      &lt;/p&gt;
    &lt;/fieldset&gt;
  &lt;% end %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>And the controller</strong></p>
  
  <pre><code>class Admin::PromotionPurchasesController &lt; ApplicationController
    layout 'admin'
    before_action :set_promotion
    before_action :set_purchase, only: [:edit, :update, :destroy]
  
    def destroy
      @purchase.destroy
      redirect_to new_admin_promotion_promotion_purchase_path(@promotion), success: 'PromotionPurchase was deleted.'
    end
  
    private
  
      def set_promotion
        @promotion = Promotion.find(params[:promotion_id])
      end
  
      def set_purchase
        @purchase = PromotionPurchase.find(params[:id])
      end
  end
  </code></pre>
  
  <p>Any ideas why I'm seeing "Are you sure?" twice instead of only once when I destroy a PromotionPurchase from the form to edit a Promotion?</p>
  
  <p>In this case, I saw it three times:</p>
  
  <p><img src="https://i.stack.imgur.com/46ICs.png" alt="A list of purchases connected to this Promotion">
  <img src="https://i.stack.imgur.com/w69HG.png" alt="The first &quot;Are you sure?">
  <img src="https://i.stack.imgur.com/woWX9.png" alt="The second">
  <img src="https://i.stack.imgur.com/8lMgN.png" alt="The third"></p>