diff options
author | Carlos Galdino <carloshsgaldino@gmail.com> | 2012-06-01 16:54:21 -0300 |
---|---|---|
committer | Carlos Galdino <carloshsgaldino@gmail.com> | 2012-07-18 10:32:17 -0300 |
commit | fb8a830a329b78a5863c1dbfb70a4005d3de60ec (patch) | |
tree | f884067efeb47391844fa75118505410dee568f5 /guides | |
parent | c08f30ff5fcda7e07cd9275a073acb2091e4b3f7 (diff) | |
download | rails-fb8a830a329b78a5863c1dbfb70a4005d3de60ec.tar.gz rails-fb8a830a329b78a5863c1dbfb70a4005d3de60ec.tar.bz2 rails-fb8a830a329b78a5863c1dbfb70a4005d3de60ec.zip |
Remove `:confirm` in favor of `:data => { :confirm => 'Text' }` option
This applies to the following helpers:
`button_to`
`button_tag`
`image_submit_tag`
`link_to`
`submit_tag`
Diffstat (limited to 'guides')
-rw-r--r-- | guides/code/getting_started/app/views/comments/_comment.html.erb | 4 | ||||
-rw-r--r-- | guides/code/getting_started/app/views/posts/index.html.erb | 2 | ||||
-rw-r--r-- | guides/source/ajax_on_rails.textile | 9 | ||||
-rw-r--r-- | guides/source/getting_started.textile | 17 | ||||
-rw-r--r-- | guides/source/layouts_and_rendering.textile | 2 |
5 files changed, 16 insertions, 18 deletions
diff --git a/guides/code/getting_started/app/views/comments/_comment.html.erb b/guides/code/getting_started/app/views/comments/_comment.html.erb index 0cebe0bd96..3d2bc1590e 100644 --- a/guides/code/getting_started/app/views/comments/_comment.html.erb +++ b/guides/code/getting_started/app/views/comments/_comment.html.erb @@ -10,6 +10,6 @@ <p> <%= link_to 'Destroy Comment', [comment.post, comment], - :confirm => 'Are you sure?', - :method => :delete %> + :method => :delete, + :data => { :confirm => 'Are you sure?' } %> </p> diff --git a/guides/code/getting_started/app/views/posts/index.html.erb b/guides/code/getting_started/app/views/posts/index.html.erb index 7b72720d50..9a0e90eadc 100644 --- a/guides/code/getting_started/app/views/posts/index.html.erb +++ b/guides/code/getting_started/app/views/posts/index.html.erb @@ -17,7 +17,7 @@ <td><%= post.text %></td> <td><%= link_to 'Show', :action => :show, :id => post.id %> <td><%= link_to 'Edit', :action => :edit, :id => post.id %> - <td><%= link_to 'Destroy', { :action => :destroy, :id => post.id }, :method => :delete, :confirm => 'Are you sure?' %> + <td><%= link_to 'Destroy', { :action => :destroy, :id => post.id }, :method => :delete, :data => { :confirm => 'Are you sure?' } %> </tr> <% end %> </table> diff --git a/guides/source/ajax_on_rails.textile b/guides/source/ajax_on_rails.textile index e23fdf9a74..26e0270a31 100644 --- a/guides/source/ajax_on_rails.textile +++ b/guides/source/ajax_on_rails.textile @@ -129,7 +129,7 @@ will produce <ruby> button_to 'Delete Image', { action: 'delete', id: @image.id }, - confirm: 'Are you sure?', method: :delete + method: :delete, data: { confirm: 'Are you sure?' } </ruby> will produce @@ -144,8 +144,8 @@ will produce </html> <ruby> -button_to 'Destroy', 'http://www.example.com', confirm: 'Are you sure?', - method: 'delete', remote: true, data: { disable_with: 'loading...' } +button_to 'Destroy', 'http://www.example.com', + method: 'delete', remote: true, data: { disable_with: 'loading...', confirm: 'Are you sure?' } </ruby> will produce @@ -217,7 +217,6 @@ link_to_remote "Delete the item", Note that if we wouldn't override the default behavior (POST), the above snippet would route to the create action rather than destroy. ** *JavaScript filters* You can customize the remote call further by wrapping it with some JavaScript code. Let's say in the previous example, when deleting a link, you'd like to ask for a confirmation by showing a simple modal text box to the user. This is a typical example what you can accomplish with these options - let's see them one by one: -*** +:confirm+ => +msg+ Pops up a JavaScript confirmation dialog, displaying +msg+. If the user chooses 'OK', the request is launched, otherwise canceled. *** +:condition+ => +code+ Evaluates +code+ (which should evaluate to a boolean) and proceeds if it's true, cancels the request otherwise. *** +:before+ => +code+ Evaluates the +code+ just before launching the request. The output of the code has no influence on the execution. Typically used show a progress indicator (see this in action in the next example). *** +:after+ => +code+ Evaluates the +code+ after launching the request. Note that this is different from the +:success+ or +:complete+ callback (covered in the next section) since those are triggered after the request is completed, while the code snippet passed to +:after+ is evaluated after the remote call is made. A common example is to disable elements on the page or otherwise prevent further action while the request is completed. @@ -307,4 +306,4 @@ JavaScript testing reminds me the definition of the world 'classic' by Mark Twai * Cucumber+Webrat * Mention stuff like screw.unit/jsSpec -Note to self: check out the RailsConf JS testing video
\ No newline at end of file +Note to self: check out the RailsConf JS testing video diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile index b00d9af00c..8d7c0d4bea 100644 --- a/guides/source/getting_started.textile +++ b/guides/source/getting_started.textile @@ -1144,7 +1144,7 @@ together. <td><%= post.text %></td> <td><%= link_to 'Show', :action => :show, :id => post.id %></td> <td><%= link_to 'Edit', :action => :edit, :id => post.id %></td> - <td><%= link_to 'Destroy', { :action => :destroy, :id => post.id }, :method => :delete, :confirm => 'Are you sure?' %></td> + <td><%= link_to 'Destroy', { :action => :destroy, :id => post.id }, :method => :delete, :data => { :confirm => 'Are you sure?' } %></td> </tr> <% end %> </table> @@ -1152,13 +1152,12 @@ together. Here we're using +link_to+ in a different way. We wrap the +:action+ and +:id+ attributes in a hash so that we can pass those two keys in -first as one argument, and then the final two keys as another argument. The +:method+ and +:confirm+ +first as one argument, and then the final two keys as another argument. The +:method+ and +:'data-confirm'+ options are used as HTML5 attributes so that when the link is clicked, -Rails will first show a confirm dialog to the user, and then submit the -link with method +delete+. This is done via the JavaScript file +jquery_ujs+ -which is automatically included into your application's layout -(+app/views/layouts/application.html.erb+) when you generated the application. -Without this file, the confirmation dialog box wouldn't appear. +Rails will first show a confirm dialog to the user, and then submit the link with method +delete+. +This is done via the JavaScript file +jquery_ujs+ which is automatically included +into your application's layout (+app/views/layouts/application.html.erb+) when you +generated the application. Without this file, the confirmation dialog box wouldn't appear. !images/getting_started/confirm_dialog.png(Confirm Dialog)! @@ -1627,8 +1626,8 @@ So first, let's add the delete link in the <p> <%= link_to 'Destroy Comment', [comment.post, comment], - :confirm => 'Are you sure?', - :method => :delete %> + :method => :delete, + :data => { :confirm => 'Are you sure?' } %> </p> </erb> diff --git a/guides/source/layouts_and_rendering.textile b/guides/source/layouts_and_rendering.textile index 55bd521419..32ceecea18 100644 --- a/guides/source/layouts_and_rendering.textile +++ b/guides/source/layouts_and_rendering.textile @@ -78,7 +78,7 @@ If we want to display the properties of all the books in our view, we can do so <td><%= book.content %></td> <td><%= link_to "Show", book %></td> <td><%= link_to "Edit", edit_book_path(book) %></td> - <td><%= link_to "Remove", book, :confirm => "Are you sure?", :method => :delete %></td> + <td><%= link_to "Remove", book, :method => :delete, :data => { :confirm => "Are you sure?" } %></td> </tr> <% end %> </table> |