user1185081
user1185081

Reputation: 2118

Destroy method does not ask for confirmation in Ruby on Rails 5.2

To avoid physical deletion of information, I added a "is_active" flag to my Business_Rule model, and modified the destroy method the following way:

def destroy
  @business_rule.set_as_inactive(current_login)
  respond_to do |format|
    format.html { redirect_to business_rules_url, notice: 'Business rule was successfully deleted.' }
    format.json { head :no_content }
  end
end

I invoke this method through a button:

<%= button_to t('Destroy'), @business_rule, confirm: t('Sure'), method: :delete, class: "buttons mid_menu" %>

Unfortunately, the confirmation does not pop-up! Thanks a lot for your ideas to solve this!

Upvotes: 1

Views: 79

Answers (1)

demir
demir

Reputation: 4709

You need to use confirm in data attribute:

<%= button_to t('Destroy'), @business_rule, data: { confirm: t('Sure') }, method: :delete, class: "buttons mid_menu" %>

Upvotes: 4

Related Questions