Created
December 23, 2010 10:18
-
-
Save anonymous/752805 to your computer and use it in GitHub Desktop.
rails 3 - Unobtrusive Javascript - link_to :submit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="myform"> | |
First name: <input type="text" name="fname" id="fname" /><br /> | |
Last name: <input type="text" name="lname" id="lname" /><br /> | |
<%= link_to "Foo", {:action => "filter", :filter => "filter1"}, {:remote => true, :method =>:get , "data-submit" => "#myform input"} %> | |
</div> | |
<script type="text/javascript" charset="utf-8"> | |
<!-- ONLY works with jquery loaded in the page --> | |
$(document).ready(function() { | |
$('a[data-remote=true]').each(function(a){ | |
$(this).bind('click', function() { | |
var href= $(this).attr('href'); | |
var url = href.split('?')[0]; | |
var data = $(this).attr('data-submit'); | |
var params = $(data).serialize(); | |
$(this).attr(url +'?'+params ); | |
}); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment