Skip to content

Commit

Permalink
Adds data-params handling for handleMethod. This allows the link_to h…
Browse files Browse the repository at this point in the history
…andler with e.g. method: "post" to add post fields from the a-tags data-params attribute to the form
  • Loading branch information
phillipp committed Feb 18, 2013
1 parent b6dae4e commit 49c06e1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/rails.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
var href = rails.href(link),
method = link.data('method'),
target = link.attr('target'),
params = link.attr('params'),
csrf_token = $('meta[name=csrf-token]').attr('content'),
csrf_param = $('meta[name=csrf-param]').attr('content'),
form = $('<form method="post" action="' + href + '"></form>'),
Expand All @@ -194,6 +195,12 @@
if (csrf_param !== undefined && csrf_token !== undefined) {
metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
}

if(params) {
for(key in params) {
metadata_input += '<input name="' + key + '" value="' + params[key] + '" type="hidden" />';
}
}

if (target) { form.attr('target', target); }

Expand Down

0 comments on commit 49c06e1

Please sign in to comment.