title: Rails-customize confirm dialog
body: <pre><code>&lt;%= link_to image_tag("icon_delete.png", :border =&gt; 0), user, method: :delete ,data: { confirm: 'Are you sure delete ' + user.email } %&gt;
  </code></pre>
  
  <p>When user clicks on this link, I want a custom confirm dialog instead of simply showing <code>confirm('Are you are')</code>.</p>
  
  <p>I've read many threads, for example <a href="http://lesseverything.com/blog/archives/2012/07/18/customizing-confirmation-dialog-in-rails/" rel="nofollow">http://lesseverything.com/blog/archives/2012/07/18/customizing-confirmation-dialog-in-rails/</a>.  However, I hit on issue <code>Sprockets::EncodingError</code>.</p>
  
  <p>Any better solution?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Everything ok before implemented customized confirmation dialog,After encoding successful, This time </p>
  
  <pre><code>&lt;%= link_to image_tag("icon_delete.png", :border =&gt; 0), user, method: :delete ,data: { confirm: 'Are you sure delete ' + user.email } %&gt;
  </code></pre>
  
  <p>Actually,When I click on delete icon,no popup show and this link didn't call destroy() in UserController.It called show() on UserController.What's going on here?</p>
  
  <pre><code>$.rails.allowAction = (link) -&gt;
  return true unless link.attr('data-confirm')
  $.rails.showConfirmDialog(link) # look bellow for implementations
  false # always stops the action since code runs asynchronously
  
  $.rails.confirmed = (link) -&gt;
  link.removeAttr('data-confirm')
  link.trigger('click.rails')
  
  
  $.rails.showConfirmDialog = (link) -&gt;
  message = link.attr 'data-confirm'
  html = """
       &lt;div class="modal" id="confirmationDialog"&gt;
         &lt;div class="modal-header"&gt;
           &lt;a class="close" data-dismiss="modal"&gt;Ã—&lt;/a&gt;
           &lt;h3&gt;Are you sure Mr. President?&lt;/h3&gt;
         &lt;/div&gt;
         &lt;div class="modal-body"&gt;
           &lt;p&gt;#{message}&lt;/p&gt;
         &lt;/div&gt;
         &lt;div class="modal-footer"&gt;
           &lt;a data-dismiss="modal" class="btn"&gt;Cancel&lt;/a&gt;
           &lt;a data-dismiss="modal" class="btn btn-primary confirm"&gt;OK&lt;/a&gt;
         &lt;/div&gt;
       &lt;/div&gt;
       """
  $(html).modal()
  $('#confirmationDialog .confirm').on 'click', -&gt; $.rails.confirmed(link) 
  </code></pre>
  
  <p>File route.rb
       root :to => "users#index"</p>
  
  <pre><code> devise_for :users, :controllers =&gt; {:registrations =&gt; "users"}
   resources :users
   match '/admin',   to: 'users#admin',   via: 'get'
  </code></pre>