diff options
Diffstat (limited to 'guides/source/ajax_on_rails.textile')
-rw-r--r-- | guides/source/ajax_on_rails.textile | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/guides/source/ajax_on_rails.textile b/guides/source/ajax_on_rails.textile index e23fdf9a74..67b0c9f0d3 100644 --- a/guides/source/ajax_on_rails.textile +++ b/guides/source/ajax_on_rails.textile @@ -28,7 +28,7 @@ the +ul+ node. h4. Asynchronous JavaScript + XML AJAX means Asynchronous JavaScript + XML. Asynchronous means that the page is not -reloaded, the request made is separate from the regular page request. Javascript +reloaded, the request made is separate from the regular page request. JavaScript is used to evaluate the response and the XML part is a bit misleading as XML is not required, you respond to the HTTP request with JSON or regular HTML as well. @@ -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 |