Skip to content

Commit

Permalink
Allow link_to with remote => true for method POST with request body. …
Browse files Browse the repository at this point in the history
…I needed this in my project for a link inside another form, wich I could not insert a form inside another form. Should be usefull for other people.
  • Loading branch information
emerleite committed May 19, 2011
1 parent 8ecc2d7 commit fd559e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/rails.js
Expand Up @@ -112,8 +112,9 @@
} else {
method = element.data('method');
url = element.attr('href');
data = null;
}
// data = null;
data = element.attr('data-body') || null;
}

rails.ajax({
url: url, type: method || 'GET', data: data, dataType: dataType,
Expand Down
5 changes: 4 additions & 1 deletion test/public/test/data-remote.js
Expand Up @@ -4,6 +4,7 @@ module('data-remote', {
.append($('<a />', {
href: '/echo',
'data-remote': 'true',
'data-body': 'data1=value1&data2=value2',
text: 'my address'
}))
.append($('<form />', {
Expand All @@ -15,11 +16,13 @@ module('data-remote', {
}
});

asyncTest('clicking on a link with data-remote attribute', 3, function() {
asyncTest('clicking on a link with data-remote attribute', 5, function() {
$('a[data-remote]')
.bind('ajax:success', function(e, data, status, xhr) {
App.assert_callback_invoked('ajax:success');
App.assert_request_path(data, '/echo');
equal(data.params.data1, 'value1', 'ajax arguments should have key data1 with right value');
equal(data.params.data2, 'value2', 'ajax arguments should have key data2 with right value');
App.assert_get_request(data);
})
.bind('ajax:complete', function() { start() })
Expand Down

0 comments on commit fd559e6

Please sign in to comment.