Skip to content

Instantly share code, notes, and snippets.

Created December 23, 2010 10:18
Show Gist options
  • Save anonymous/752805 to your computer and use it in GitHub Desktop.
Save anonymous/752805 to your computer and use it in GitHub Desktop.
rails 3 - Unobtrusive Javascript - link_to :submit
<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