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
Ruby Class Instance Variables and Inheritance
Error Running 'Requirements_Osx_Brew_Libs_Install...' on MAC 10.7
Understanding Method_Added for Class Methods
If Else Statements in .Html.Erb in Views
In Ruby, How to Read Data Column Wise from a CSV File
Adding Keywords to Ruby Syntax Highlighting for Notepad++
How to Remove Repeated Spaces in a String
How to Check for Stdin Input in a Ruby Script
How to Establish a Ssl Enabled Tcp/Ip Connection in Ruby
How to Configure Mongomapper and Activerecord in Same Ruby Rails Project
Rails - Displaying Foreign Key References in a Form
Is Time.Zone.Now.To_Date Equivalent to Date.Today
Rails 4 User Roles and Permissions
Write and Read a File with Utf-8 Encoding
Spork 0.9.2 and Rspec 3.0.0 = Uninitialized Constant Rspec::Core::Commandline (Nameerror)
Rails 3: Call Functions Inside Controllers
How to Iterate Through an Array Starting from the Last Element? (Ruby)