Ask A Question

Notifications

You’re not receiving notifications from this thread.

How Do i add an "Are You Sure?" button in my update controller

Neil Patel asked in Rails

Hi

I want add a pop up button that says "Are you sure" when the user clicks on submit ? if it was a destroy mehod it would be something like this method: :delete, data: { confirm: "Are you sure?"} but not sure how to do it on the update method

def update
    if donation_plan.update(donation_plan_params)
      redirect_to :back, notice: "Thank you for your Gift Aid Donation"
    else
      render :show
    end
  end

or do i add this to the show page

 = simple_form_for donation_plan, url: my_donations_path do |f|
                  = f.input :giftaid, inline_label: " reclaim Gift Aid of 25p, in every £1 on past donations and all future donations I may make.", label: false
                  %p= f.submit "Submit", class: "btn btn-primary"
Reply

I think its this
%p= f.submit "Submit", class: "btn btn-primary", data: { confirm: "Are you Sure"}

Reply

Yeah, data-confirm is just a generic attribute you can use on any clickable item, not just delete links. That should work fine.

Reply

thanks chris!

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,677+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.