code_L
code_L

Reputation: 49

How to ask for confirmation before performing an actionin ruby on rails?

I have a delete button where I want to ask for confirmation before deleting the record. I want to put a custom message in German and German terms for 'OK' and 'cancel'.

<%= button_to 'Record löschen', action: 'delete_all_record', id: params[:id], redirect_back: params[:redirect_back]%>

so, when I press record löshen button it should ask for confirmation and then perform the deletion action.

Upvotes: 0

Views: 296

Answers (2)

installero
installero

Reputation: 9776

Just a quick tip for rails 7

<%= button_to 'Record löschen',
  {action: 'delete_all_record', id: params[:id]},
  form: {data: {turbo_confirm: 'Sind Sie sicher?'}} %>

Upvotes: 0

spickermann
spickermann

Reputation: 106882

You could use button_to with the data attribute confirm like this:

<%= button_to(
      'Record löschen', 
      { action: 'delete_all_record', id: params[:id] },
      data: { confirm: "Sind Sie sicher?" } %>

Upvotes: 1

Related Questions