How to Add Confirm Message with Link_To Ruby on Rails

How to add confirm message with link_to Ruby on rails

First, you should verify that your layout have jquery_ujs.
Best practice to do it by including it in your main application.js:

//= require jquery_ujs

Check that you included application.js in your layout:

= javascript_include_tag :application

While, in development mode, view your source html and verify jquery_ujs.js exists.

Run your server and verify your link tag has data-confirm value, for example:

<a href="/articles/1" data-confirm="Are you sure?" data-method="delete">

If all those steps are correct, everything should work!

Note: check this RailsCast http://railscasts.com/episodes/136-jquery-ajax-revised

Rails 4 - link_to with confirm in Rails

Confirm has been deprecated in rails 4.

So use new syntax:

<%= link_to "title", "#", data: {confirm: "Are you sure!"} %>

rails 3, how add a simple confirmation dialog when user clicks a link

EDIT:
<%= link_to "Do something", {:controller => "foo", :action => "bar"}, :confirm => "Are you sure you want to do that?" %>

link_to confirm not working with controller/action

Not sure why the hash syntax matters but I use

<%= link_to 'text', path(param), data: { confirm: 'confirmation' } %>

Edit:

Specifying controller and action it would be:

<%= link_to 'text', { controller: 'bedsheet_lines', action: 'create_new_bedsheet_line' }, data: { confirm: 'confirmation' } %>

Show alert message after confirm message with link_to rails

Use sweetalert

Look for the "A warning message, with a function attached to the "Confirm"-button..." example

There is a gem for sweetalert

:confirm in rails not working

I had to add my confirm attribute inside the data attribute to get it to work. I am using rails 4 with bootstrap. I hope this helps someone else who has that issue.

link_to 'Delete', @rule, method: :delete, data: { confirm: 'Are you sure you want to delete this alert?' }


Related Topics



Leave a reply



Submit