I have a button that should open up a popup but instead reloads the page. I use link_to which works, but the button_to doesn’t. Changing the button_to to a GET request doesn’t work. How do I force it?
<%= button_to "Invite your friends", :id => "invite_fb_friends" %>
<div id="fb-root">
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
$(function(){
$("a#invite_fb_friends").click(function(event) {
FB.init({
appId:'255295947482349',
cookie:false,
status:true
});
FB.ui({
method: 'apprequests',
message: 'This is a test message.'});
event.preventDefault();
return false;
});
});
</script>
</div>
Resulting HTML:
#For the button
<form method="post" action="/profile?id=invite_fb_friends" class="button_to">
<div><input type="submit" value="Invite your friends" />
<input name="authenticity_token" type="hidden" value="1bgr+0o9j/gs4sgD7hItkc3BFR1ewVh5VyXCZRoMrtY=" />
</div></form>
#For the link
<div id="friends">
<p><a href="#" id="invite_fb_friends">invite your friends</a></p>
button_to generates a form with a submit button that posts the form.
Maybe you should try link_to or just regular markup: