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

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"

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

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

Join the discussion

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.