0

I am working on Users' Registration and want to give the User a possibility to quit registration process, if the don't want to fill out the address in the second step of my form. For this case I created a "Quit"-button and had in my view defined:

<%= link_to "Quit", @user, method: :delete, data: { confirm: "Your data won't be saved. Proceed?" },  class: 'btn form margin button-align' %>

This worked, but I didn't like the style of my alert window and found some tips, how to change it here. So, I changed my view as follows (just part of it):

class="modal-title" id="myModalLabel"> Your data won't be saved! </h4>
          </div>
          <div class="modal-body">
            Are you sure you want to quit the registration process?
            <%= link_to "Yes", @user, root_path, method: :delete %>/
            <%= link_to "No", "javascript:void(0)",'data-dismiss': "modal" %>
          </div>
        </div>
      </div>
    </div>

...

<div class="column">
<%= link_to "Quit", "javascript:void(0)", 'data-target': "#myModal", 'data-toggle': "modal",  class: 'btn form margin button-align' %>
</div>

But it shows me the error above. What's wrong?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Katharina Schreiber
  • 1,187
  • 2
  • 11
  • 38

1 Answers1

1

Since Rails 6, it is easy to override the confirm dialog with Rails-UJS. See the PR here: https://github.com/rails/rails/pull/32404

With my colleague, we have made an example commit here: https://github.com/perangusta/one-day-in-rails6-world/commit/5134bb8ccd48bc37ff1dfccffb7e0801e63b0af8

You should be able to easily adapt the code in your context.

  • Thanks! I used this [link](https://www.botreetechnologies.com/blog/make-your-javascript-alerts-and-confirmation-boxes-more-fancier-in-10-minutes). It worked perfectly too! – Katharina Schreiber Jan 26 '20 at 19:15